简体   繁体   English

Heroku 上的 413(请求实体太大)带有 Node.JS 和 Create-React-App BuildPack

[英]413 (Request Entity Too Large) on Heroku w/ Node.JS and Create-React-App BuildPack

I've been scrambling the interwebs for the past 3 days, seemingly running in circles with no solution.在过去的 3 天里,我一直在打乱互联网,似乎绕圈子没有解决方案。

We've been building the application on a locally, with create-react-app and an Express.js backend.我们一直在本地构建应用程序,使用 create-react-app 和 Express.js 后端。 There are no issues with uploading files (of any type) on the local instance.在本地实例上上传文件(任何类型)没有问题。 We've since deployed to Heroku, having separate dynos for the frontend and the backend, using a proxy.我们已经部署到 Heroku,使用代理为前端和后端提供单独的 dynos。 As it stands, there is no nginx.conf file that can be located.就目前而言,没有可以找到的 nginx.conf 文件。 Everything says we're running nginx, but no editable config file.一切都说我们正在运行 nginx,但没有可编辑的配置文件。 Despite this, when trying to upload on the Heroku deployed site, a Failed to load resource: the server responded with a status of 413 (Request Entity Too Large) error is triggered when making the POST request.尽管如此,当尝试在 Heroku 部署的站点上上传时,无法加载资源:在发出 POST 请求时,会触发服务器响应状态为 413(请求实体太大)错误。

I've tried adding:我试过添加:

  // Body Parser Middleware
  app.use(bodyParser.json({ limit: "500mb" }));
  app.use(
    bodyParser.urlencoded({
      limit: "500mb",
      extended: true,
      parameterLimit: 5000000
    })
  );

We use Multer for multipart uploads which is what this concerns (uploading files, specifically audio files)我们使用 Multer 进行分段上传,这就是问题所在(上传文件,特别是音频文件)

That's as follows:如下:

const maxSize = 50 * 1024 * 1024; //30 MB

/*
Profile Upload
*/
const upload = multer({
  storage: storage,
  limits: { fileSize: maxSize, fieldSize: maxSize }
});

Furthermore, in the static.json for the frontend React.js side, the following has been added:此外,在前端 React.js 端的 static.json 中,添加了以下内容:

{
"max_body_size": "50m",
}

Every solution suggested on both Stackoverflow and Github has been attempted.已经尝试了 Stackoverflow 和 Github 上建议的每个解决方案。 Are we missing something here?我们在这里遗漏了什么吗? To simulate the error for yourself: https://www.trakz.co/upload w/ email as tester@gmail.com and password as testpass为自己模拟错误: https ://www.trakz.co/upload w/电子邮件为 tester@gmail.com 密码为 testpass

I fixed the problem on the backend written in Node.js and Express.js by increasing the limit of json .我通过增加jsonlimit解决了使用Node.jsExpress.js编写的后端的问题。 You can refer to this snippet of code below for your reference:您可以参考下面的这段代码以供参考:

app.use(express.json({limit: '50mb'}));
app.use(express.urlencoded({limit: '50mb'}));

For Express v4.16.0+ then you use express.json else you can use bodyparser对于Express v4.16.0+然后你使用express.json否则你可以使用bodyparser

app.use(express.bodyParser({limit: '50mb'}));
app.use(express.urlencoded({limit: '50mb'}));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM