在nodejs

时间:2016-11-15 15:38:35

标签: node.js express multer

我正在使用带有nodejs的Multer版本1.2.0,每当我尝试在base64中上传图像时出现错误 - 错误:字段值太长 的错误

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) 

代码:

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');
});

无法理解我失踪的地方,请提出任何建议。    提前谢谢。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

使用limit选项增加字段数据限制:

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

refer link