not getting the url or secureUrl in the response from the cloudinary
here you can see that how i am uploading the image to the cloudinary ,
try {
// Extract the file stream from the File object
const stream = file.stream();
const result = await cloudinary.uploader.upload_stream(stream, { resource_type: 'image' });
const imageUrl = result.secure_url;
console.log('image url: ', imageUrl);
return Response.json({ success: true, data: { ...result, imageUrl } });
} catch (error) {
console.error("cloudinary error: ", error);
return Response.json({ success: false, message: 'Failed to upload image' });
}
Note: i am trying with the Next.js server side component
but in the imageUrl i am getting “undefined”
and here you can see that what response i am getting from the cloudinary
-
Hi Ankit,
Here are a few things you could check:
Ensure that the
file.stream()
is correctly providing a stream of data. You might want to log the stream data to see if it's correctly formed.The
upload_stream
function is asynchronous, so it's recommended to wrap it in a promise. Make sure you're correctly handling the promise and any potential errors.Check the
result
object returned by theupload_stream
function. Thesecure_url
should be a property of this object. If it's not present, there might be an issue with the upload itself.Make sure that your Cloudinary setup (like
cloud_name
,api_key
, andapi_secret
) is correctly configured.You can find some code examples here:
https://cloudinary.com/blog/guest_post/media-uploads-with-cloudinarys-upload-functions#upload_stream
https://cloudinary.com/documentation/node_image_and_video_upload#node_js_upload_stream
Here is another example :
// Stream upload var upload_stream = cloudinary.uploader.upload_stream({ tags: 'basic_sample' }, function (err, image) { console.log(); console.log("** Stream Upload"); if (err) { console.warn(err); } console.log("* Same image, uploaded via stream"); console.log("* " + image.public_id); console.log("* " + image.url); waitForAllUploads("pizza3", err, image); }); fs.createReadStream('pizza.jpg').pipe(upload_stream);
I hope you find it useful.
Regards,
Wissam
0
Post is closed for comments.
Comments
1 comment