I'm trying to integrate Cloudinary in my project for uploading images. I have just started using the following links:
http://cloudinary.com/documentation/node_image_upload https://github.com/cloudinary/cloudinary_npm/blob/master/samples/basic/basic.js
I'm stuck at a point where I can see the image uploaded to Cloudinary in my dashboard but in my code the response is undefined.
Code:
cloudinary.config(config.cloudinaryConfig);
function uploadFileInCloudinary(fileObj, callback) {
console.log(fileObj);
if(fileObj && (fileObj != undefined)) {
console.log(fileObj['path']);
cloudinary.uploader.upload(fileObj['path'], function(err, result) {
if(err) {
callback(err);
}
console.log("cloudinary result");
console.log(JSON.stringify(result)); // undefined
callback(null, result);
});
} else {
callback("error");
}
}
Why is it so? Can anyone give me some pointers to where am I doing wrong?
By default, uploading is performed synchronously. Once finished, the uploaded image or video is immediately available for manipulation and delivery. An upload call returns
,
You need to define a return statement before you initiate a callback
response
doing this should take away the undefined
error
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.