首页 > 解决方案 > 使用 Cloudinary 上传图像时,Node js 应用程序不显示错误

问题描述

我在将图像上传到 cloudinary 的 heroku 上部署了我的节点 js 应用程序。它在我的本地机器上正常运行,但是当我在 heroku 上运行它时,我得到 TypeError: Cannot read property 'url' of undefined。请帮助我在这里做错了什么?

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);
            }
        });
    }
);

});

标签: node.jsmongodbexpressherokucloudinary

解决方案


推荐阅读