如何仅更新用户模型的cloudinary图像?

时间:2016-08-04 11:46:05

标签: cloudinary keystonejs

没有用于演示clodinary Image更新的代码。 我在下面写的代码确实更新了Image但是我不能立即使用FIll或者限制cloudinary Image的方法。

cloudinary.uploader.upload(req.files.icon.path, function(img, err) { 
    console.log(img) 
    if(err){
        res.send(err);
    }else{
        req.user.update({$set: {icon: img}}, function (err, count) {
            res.send(img.fill(300,300));// this line says fill not defined.
           //res.send(_img.fill(300,300));// this also fails
        });
    }
});

1 个答案:

答案 0 :(得分:1)

请注意,返回的img不是实际图片,而是图片详细信息的结果JSON。\ n \ n 另外,请查看the documentation以了解如何生成转换。具体来说,要应用300x300填充裁剪,您需要在网址中添加c_fill,h_300,w_300,这可以通过以下类似方式实现:

cloudinary.image(img.public_id, { format: "jpg", width: 100, height: 150, crop: "fill" })