2016-11-15 110 views
0

我使用Multer 1.2.0版本,擁有的NodeJS,每當我試圖用base64得到錯誤--error上傳圖片:字段值太長 錯誤文件上傳中的NodeJS

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

無法理解我在哪裏丟失,好心建議什麼。 預先感謝您。

+0

您是否嘗試在/ admin/uploadpicture路徑中設置upload.single('field')'而不是'upload'? – bpinhosilva

+0

我必須一次上傳四張圖片,這就是爲什麼我使用 var upload = multer({storage:storage})。any() – viswa

回答

0

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