Can't Get Image_id From Cloudinary In Nodejs
I'm using Node.js and Express. I just implement Cloudinary to upload image from user, and store the image id to my MySQL database. I tried this tutorial from Cloudinary's documenta
Solution 1:
I guess the docs in cloudinary site is wrong or outdated. Try verifying your upload as below. It should work.
router.post('/submit/idea', function(req, res, next){
/*REMOVE THESE PARTS. I guess these are not needed any more.
var url = require('url')
var url_parts = url.parse(req.body.coverurl, true)
var query = url_parts.query
*///Directy pass coverurl to PreloadedFile method. var preloaded_file = new cloudinary.PreloadedFile(req.body.coverurl)
if (preloaded_file.is_valid()) {
var image_id = preloaded_file.identifier()
console.log("Img ID:" + image_id);
// add image_id to mysql
} else {
console.log("Invalid upload signature")
}
})
Solution 2:
Yalamber got it right. Our documentation is out of date! 😟
Because the form uses POST
and not GET
, the image_id field is provided in the body of the request rather than the URL query parameters.
You can see the correct behaviour in our sample project photo_album, specifically in create_direct()
(abridged below):
functioncreate_direct(req,res){
var photo = newPhoto(req.body);
var image = new cloudinary.PreloadedFile(req.body.image_id);
if (image.is_valid()){
photo.image = image.toJSON();
}
photo.save().then(function(photo){
console.log('** photo saved');
}).catch(function(err){
console.dir(err);
}).finally(function(){
res.render('photos/create_direct',{photo:photo,upload:photo.image});
});
}
Thanks for noticing! We will update our documentation very soon.
-- Cloudinary
Post a Comment for "Can't Get Image_id From Cloudinary In Nodejs"