4

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.

2
  • Have you tried setting upload.single('field') instead of upload in your /admin/uploadpicture route? Commented Nov 15, 2016 at 15:47
  • I have to upload four images at a time that's why I am using var upload = multer({ storage: storage }).any() Commented Nov 16, 2016 at 15:25

3 Answers 3

9

Increase the field data limit using the limits option:

multer({
  limits: { fieldSize: 2 * 1024 * 1024 }
})

refer link

Sign up to request clarification or add additional context in comments.

Comments

0

you can use upload.array('field') to upload as many files as you want.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.