【问题标题】:express-fileupload - how to allow big files uploadexpress-fileupload - 如何允许大文件上传
【发布时间】:2018-10-16 23:18:24
【问题描述】:

我正在使用 express-fileupload npm 包进行多部分文件上传。我需要上传多个文件,大小可以超过默认允许的 100kb 大小。我还为文件上传添加了以下配置以允许大文件,但没有运气。

const fileUpload = require('express-fileupload');
app.use(fileUpload({
    limits: { fileSize: 50 * 1024 * 1024 },
  }));
app.use(bodyParser.urlencoded({
    extended: true
}));

// parse requests of content-type - application/json
app.use(bodyParser.json());

如果我缺少任何设置,请告诉我。

【问题讨论】:

    标签: node.js express file-upload multipartform-data


    【解决方案1】:

    好吧,我必须首先将 bodyParse.json() 放在 JSON 和任何其他形式的数据(urlencoded 和 multipart)上正常工作。 app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true }));

    【讨论】:

      【解决方案2】:

      express-fileupload 默认对文件大小没有任何限制。 所以我可以建议您使用的一些服务限制。

      还有一件事,建议对大文件使用选项 useTempFiles。

      当 useTempFiles 为 true 时,中间件使用临时文件而不是内存来管理上传过程。

      例如

      app.use(fileUpload({
          useTempFiles : true,
          tempFileDir : '/tmp/'
      }));
      

      【讨论】:

        猜你喜欢
        • 2018-01-31
        • 1970-01-01
        • 1970-01-01
        • 2019-02-07
        • 2020-01-29
        • 2015-12-30
        • 1970-01-01
        • 2021-03-22
        • 1970-01-01
        相关资源
        最近更新 更多