我正在尝试在快速应用程序中使用multer将不同类型的文件上传到服务器。但是每次服务器通过声明TypeError进行响应:req.files都不可迭代。我检查了一下,req.files为空。
以下是同一代码:
val str= " This string has " , need to escape with \ .Even string has \ before"
val resultShouldbe=" This string has \" ,need to escape with \\.Even string has \\ before"
str.replace(""""""" , """\"""").replace("\\","\\\\")
这就是我从邮递员那里调用此API的方式: Postman UI
我无法弄清楚问题出在哪里。请帮助我。
答案 0 :(得分:0)
我运行了他的代码,他试图将图像存储在我的文件系统的根目录中。
要引用相对于当前目录的路径,您需要使用./
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'uploads/') // change 'upload/' to './uṕload'
},
filename: function (req, file, cb) {
cb(null, Date.now() + '-' + file.originalname)
}
})
此后,代码开始工作。