使用Cloudinary上传图像时,Node js应用程序未显示错误

时间:2018-11-29 03:36:26

标签: node.js mongodb express heroku cloudinary

我在heroku上部署了节点js应用程序,该应用程序将图像上传到cloudinary。它在我的本地计算机上正常运行,但出现TypeError:在heroku上运行时无法读取未定义的属性“ url”。请帮助我在这里弄错了吗?

app.post('/vehicles', multipartMiddleware, (req, res) => {
cloudinary.v2.uploader.upload(req.files.image.path,
    { width: 300, height: 300, crop: "limit", tags: req.body.tags, moderation: 'manual', timeout: 60000 }, 
    (err, result) => {
        console.log(result);

        var vehicle = new Vehicle({
            name: req.body.name,
            price: req.body.price,
            transmission: req.body.transmission,
            seat_number: req.body.seat_number,
            milleage: req.body.milleage,
            event: req.body.event,
            category: req.body.category,
            //Stores the url in a DB for future use
            image: result.url,
            image_id: result.public_id
        });

        //Creates a new Vehicle and Add to db
        vehicle.save((err, newVehicle) => {
            if (err) {
                res.redirect("/dashboard")
                console.log(err)
            } else {
                res.redirect("/vehicles")
                // console.log(newVehicle);
            }
        });
    }
);

});

0 个答案:

没有答案