'file uploading with Multer in nodejs
I am using Multer version 1.2.0, with nodejs, whenever i am trying to upload an image in base64 getting error --Error: Field value too long Error
Error: Field value too long
at makeError (C:\xampp\htdocs\sitename\node_modules\multer\lib\make-error.js:12:13)
at abortWithCode (C:\xampp\htdocs\sitename\node_modules\multer\lib\make-middleware.js:77:22)
at Busboy.<anonymous> (C:\xampp\htdocs\sitename\node_modules\multer\lib\make-middleware.js:83:34)
at Busboy.emit (events.js:118:17)
at Busboy.emit (C:\xampp\htdocs\sitename\node_modules\multer\node_modules\busboy\lib\main.js:31:35)
at PartStream.onEnd (C:\xampp\htdocs\sitename\node_modules\multer\node_modules\busboy\lib\types\multipart.js:261:15)
at PartStream.emit (events.js:129:20)
at Dicer.onPart (C:\xampp\htdocs\sitename\node_modules\multer\node_modules\busboy\lib\types\multipart.js:120:13)
at Dicer.emit (events.js:107:17)
at Dicer.emit (C:\xampp\htdocs\sitename\node_modules\multer\node_modules\busboy\node_modules\dicer\lib\Dicer.js:80:35)
Code:
var multer = require('multer');
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './photos')
},
filename: function (req, file, cb) {
cb(null, file.fieldname + '-' + Date.now())
}
})
var upload = multer({ storage: storage }).any()
app.post('/admin/uploadpicture', upload, function(req, res) {
res.send('Test');
});
Not able to understand where i am missing, kindly suggest anything. Thank you in advance.
Solution 1:[1]
Increase the field data limit using the limits option:
multer({
limits: { fieldSize: 2 * 1024 * 1024 }
})
Solution 2:[2]
you can use upload.array('field') to upload as many files as you want.
Solution 3:[3]
if after adding the limits to multer you are still seeing this issue, it is likely because you are attempting to upload the same image multiple times and it is having trouble over riding the previous image. i've uploaded a new pic
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gautam |
| Solution 2 | Riya Saxena |
| Solution 3 | Amin Kedir |
