你好,我的问题是我使用multer将它们存储在我的服务器上,并将它们的路径存储在mongodb上,但我无法将它们显示在我的react应用程序上。
提前感谢您的帮助。
您需要在FormData中发送来自React的数据,例如:
节点
import multer from "multer" // const multer = require("multer")
const upload = multer()
// in your route
app.post("/any-route", upload.array("name_id", 10), () => {
let file = null
if (req.files && req.files.lenght > 0){
file = req.file[0]
}
// and this file you can send to MongoDB
})
在react中,您需要使用FormData
const FormData = new FormData()
FormData.append("name_id", file) // this file is the file you want send