【问题标题】:How to update only the cloudinary Image of a User model?如何仅更新用户模型的云图像?
【发布时间】:2016-08-04 11:46:05
【问题描述】:

没有演示更新clodinary 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
        });
    }
});

【问题讨论】:

    标签: cloudinary keystonejs


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,我从您的回复中学到的最重要的一点是,我可以使用 img.public_id 作为参数,我猜这没有记录在案。我使用了这个函数 cloudinary.url(img.public_id, { format: "jpg", width: 100, height: 150, crop: "fill" }) 而不是你建议的。
    • 你是对的。 cloudinary.url 在这种情况下会更有意义。很高兴我能帮上忙。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-26
    • 1970-01-01
    • 2020-11-16
    • 2012-03-15
    • 2018-08-15
    • 1970-01-01
    相关资源
    最近更新 更多