javascript - Multer [NodeJS] 用于多个字段

标签 javascript node.js express multer

用于多个字段的 Multer。

我想通过文件字段上传图像(一张图像),以及通过“Summernote”上传图像。

这都是一个 Controller 。如何使用 multer 实现工作?

upload.single()upload.array()

如何正确实现?

当我通过“Summernote”上传时,出现错误:

MulterError: Unexpected field", because there is a conflict with the fields.

此刻:

router.post('/create', upload.single('cover'), post.savePost)

最佳答案

我解决了这个问题:

router.post('/create', upload.fields([{
    name: 'cover',
    maxCount: 1,
}, {
    name: 'files'
}]), post.savePost)

关于javascript - Multer [NodeJS] 用于多个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55198942/

相关文章:

node.js - 如何从 Atmosphere 编辑不在 GitHub 上的 Meteor 包?

node.js - 在 typescript 中使用 allowJs = true 时在 node_modules 中缺少 ./lib 文件

javascript - 幻灯片上的图像向下跳跃

javascript - jquery 和 javascript 混合 : How to pass the name to jquery selector

node.js - Nodejs Express 服务器未关闭

javascript - 在 node.js 中从何处以及如何提供文件

javascript - 为什么在express js中间件中调用函数表达式会被提升?

json - body-parser读取json post数据node.js express

javascript - 使用javascript将css类添加到td标签

javascript - 如何使用 setInterval() 制作动画?