【发布时间】:2018-07-21 09:22:43
【问题描述】:
我正在尝试处理 Multer 中的上传文件计数。我的功能如下:
export const upload = multer({
storage: storage,
fileFilter: (req, file, callback) =>
Table.findOne({'user': req.user._id})
.then(table => {
if (req.params.type === 'gallery' && table.gallery.length + req.files.length > 10) {
req.tooManyGalleryImages = true
return callback(null, false, new Error())
}
callback(null, true)
}),
limits: {
fileSize: 2000000
}
})
我需要 req.files.length 但例如,如果我上传三个文件,它会使用一个元素数组返回 req.files 三次。也许还有其他功能可以让我在上传之前比较文件数?
【问题讨论】:
标签: javascript node.js express multer