我正在使用multer-storage-cloudinary上载图像,然后获取cloudinary生成的图像URL,该URL将保存到mongoDB Cloud Service中。我试过在本地主机上运行,并且工作正常。但是,部署到heroku之后,运行命令heroku logs --tail
2020-10-15T06:20:08.110693+00:00 app[web.1]: (node:23) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'path' of undefined
这是我的代码:
控制器
async (req, res, _next) => {
await Models.Users.user_detail.create(
{
gender: req.body.gender,
birth_date: req.body.birth_date,
image_URL: req.file.path,
created_at: moment(),
user_id: req.body.user_id,
},
(err) => {
if (err) {
res.json(SERVER_ERROR(err));
} else {
res.json(OK("data successfully added"));
}
}
)
路线
router.post(
"/detail/create",
multer({ storage: Storage.storageConfig }).single("image_URL"),
UserDetail.create)
存储配置
new CloudinaryStorage({
cloudinary: cloudinary.v2,
params: {
folder: async (req, file) => "user",
},
})
Cloudinary配置
import cloudinary from "cloudinary"
cloudinary.v2.config({
cloud_name: global.env.CLOUDINARY_NAME,
api_key: global.env.CLOUDINARY_API_KEY,
api_secret: global.env.CLOUDINARY_API_SECRET,
})
export default cloudinary
谁能解释我为什么?谢谢!