我正在尝试将一组图像发送到我的后端,然后使用 multer-s3 上传它们。我通过 react 将它们发送到 Node express 后端。当我从前端提交时,它是提交一组图像,如下所示:
图像:[ 文件(3195869){名称:“IMG - example.JPG”,lastModified:1514505624000,lastModifiedDate:2017 年 12 月 28 日星期四 17:00:24 GMT-0700(MST),webkitRelativePath:“”,大小: 3195869,……},……]
但是当我在后端记录 req.body 时,它返回 [ {}, {}, {}, ... ] 并且 req.files 未定义
为什么文件无法通过发布请求?
最佳答案
Usage中有解释部分^^
app.post('/photos/upload', upload.array('photos', 12), function (req, res, next) {
// req.files is array of `photos` files
// req.body will contain the text fields, if there were any
})
就像express js所说:
"In Express 4, req.files is no longer available on the req object by default. To access uploaded files on the req.files object, use multipart-handling middleware like busboy, multer, formidable, multiparty, connect-multiparty, or pez."
对您来说这是一个很好的教程,其中包含您要上传多个文件的部分:https://scotch.io/tutorials/express-file-uploads-with-multer#toc-upload-multiple-files
关于node.js - 如何将文件数组发送到express后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48085568/