文件上传对于大型文件不断崩溃-NodeJS

问题描述 投票:1回答:1

我正在使用React在前端使用Axios发出发布请求,以发送带有表单数据的文件...。但是,如果文件大小约为5到10 MB,则有时会崩溃

var multer = require("multer");
var storage = multer.diskStorage({
  destination: function(req, file, cb) {
    cb(null, "public/uploads");
  },
  filename: function(req, file, cb) {
    cb(null, Date.now() + file.originalname);
  }
});

module.exports = multer({ storage: storage });

router.post("/", auth.isAdmin, upload.array("files", 5), (req, res) => {
console.log(req.files);
})

控制台显示文件信息,但应用程序不断崩溃...我似乎无法弄清原因...有时它可以工作,有时却不能。我认为这与文件大小有关

javascript node.js multer
1个回答
0
投票

您可以提高限制:

app.use(bodyParser.json({limit: '10mb', extended: true}))    
app.use(bodyParser.urlencoded({limit: '10mb', extended: true}))

和:

var storage = multer({storage: storage, limits: {fileSize: 10MB, 
fieldSize: 10MB}}).diskStorage({
    destination: function(req, file, cb) { ...
© www.soinside.com 2019 - 2024. All rights reserved.