0
什麼是「upload.array(‘照片’,3)」在下面的代碼表示....我在使用multer-S3上傳圖像到AWS S3存儲
我的HTML代碼完全昏。 (代碼減少簡潔)
<form action="/upload" method="POST">
<input type="file" name="pic" id="pic" accept="image/*">
<input type="submit">
</form>
我expressjs代碼
AWS.config.update({
accessKeyId: "xxxxxxxxxxxxx",
secretAccessKey: "yyyyyyyyyy",
"region": "zzzzzzzzz" ,
signatureVersion: 'v4'
});
var s3=new AWS.S3();
var upload = multer({
storage: multerS3({
s3: s3,
bucket: 'imgcontainer',
metadata: function (req, file, cb) {
cb(null, {fieldName: file.fieldname});
},
key: function (req, file, cb) {
cb(null, Date.now().toString())
}
})
})
app.post('/upload', upload.array('photos', 3), function(req, res, next) {
res.send('Successfully uploaded ' + req.files.length + ' files!')
})
輸出:
Cannot read property 'length' of undefined
感謝您的回覆mscdex,「upload.array(」pic「,3)」...那麼3代表..... –
[文檔](https://github.com/expressjs/multer #arrayfieldname-maxcount)解釋它,它是'maxCount'參數(強制文件字段名稱的最大文件限制)。 – mscdex
相同的錯誤「即使在將照片更改爲圖片後,也無法讀取未定義的屬性'長度'......抱歉 –