I am using React for the front end using Axios to make a post request to send files with form data.... But if the file size is around 5 to 10 MB it sometimes crashes
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);
})
The console shows the file information but the app keeps crashing... I cannot seem to figure out why... sometimes it works and sometimes it doesn't. I think it has something to do with the file size
you can improve limits:
app.use(bodyParser.json({limit: '10mb', extended: true}))
app.use(bodyParser.urlencoded({limit: '10mb', extended: true}))
and:
var storage = multer({storage: storage, limits: {fileSize: 10MB,
fieldSize: 10MB}}).diskStorage({
destination: function(req, file, cb) { ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.