0

There is not code which demonstrate the update of clodinary Image. The code I have written below do update the Image but then I can not immediately use the FIll, or limit method of 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
        });
    }
});
Drew
  • 24,851
  • 10
  • 43
  • 78
enRaiser
  • 2,606
  • 2
  • 21
  • 39

1 Answers1

1

Note that the img that's returned isn't the actual image, it's a result JSON of the image's details. Also, please have a look at the documentation to see how transformations are generated. Specifically, to apply a 300x300 fill crop, you need to add c_fill,h_300,w_300 to the URL, which could be achieved with something similar to:

cloudinary.image(img.public_id, { format: "jpg", width: 100, height: 150, crop: "fill" })
Itay Taragano
  • 1,901
  • 1
  • 11
  • 12
  • Thanks the most important thing I learned from your response is that I can use img.public_id as parameter, that was not documented I guess. I used this function cloudinary.url(img.public_id, { format: "jpg", width: 100, height: 150, crop: "fill" }) instead of what u suggested. – enRaiser Aug 09 '16 at 08:19
  • You're right. `cloudinary.url` would make more sense in this case. Glad I could help. – Itay Taragano Aug 10 '16 at 19:41