简体   繁体   中英

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.

您可以使用upload.array('field')上传所需数量的文件。

Increase the field data limit using the limits option:

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

refer link

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM