node.js - 无法使用 cloudinary 上传图片
问题描述
我无法将图像上传到 cloudinary,我认为这与我放置 cloudinary 上传器功能有关,据说我已尝试重组但它仍然无法正常工作。
抱歉,我错过了错误!“typeError 无法读取‘路径’的属性。
userRouter.post('/property', upload.single('propertyImage'),passport.authenticate('jwt',{session : false}),(req,res)=>{
console.log(req.files);
const property = new Property({
street: req.body.street,
town: req.body.town,
area: req.body.area,
PostCode: req.body.PostCode,
NoBeds: req.body.NoBeds,
NoBath: req.body.NoBath,
NoLivingRooms: req.body.NoLivingRooms,
askingPrice: req.body.askingPrice,
propertyImage: image_url
});
const {propertyImage} = files;
cloudinary.uploader.upload(
propertyImage.path,
{ folder: "/houseImage/" },
async (error, results) => {
const image_url = results.url;
property.save(err=> {
if(err)
res.status(500).json({message : {msgBody: "Error has occured", msgError : true}});
else{
req.user.properties.push(property);
req.user.save(err=> {
if(err)
res.status(500).json({message : {msgBody: "Error has occured", msgError : true}});
else
res.status(200).json({message: {msgBody: "Successfully created property", msgError : false}});
})
}
})
});
解决方案
推荐阅读
- checkstyle - 是否有强制类中的每个字段都有注释的检查样式规则?
- python - 添加事件回调到 kivy RecycleView
- c# - C# 为对象列表创建 Mock Configuration.GetSection(“Section:SubSection”)
- reactjs - 使用 validate 函数进行验证时出现 React Hook Form 问题
- regex - 在模式匹配正则表达式中使用“或”
- git - 无法从 git --cached rm 目录
- python - 嵌套的 for 循环总是很慢吗?
- ios - 从 API 获取数据时,iOS 应用程序在滚动时崩溃
- mysql - SQL:在另一个表中记录存在性检查
- google-cloud-platform - 带有 Firebase 身份验证的 ESPv2 的 JWT 验证失败