const fetch = require('node-fetch');
const cloudinaryUrl = 'YOUR_CLOUDINARY_URL';
const imagePublicId = 'YOUR_IMAGE_PUBLIC_ID';
const fetchImageFromCloudinary = async () => {
const cloudinaryApiUrl = `https://res.cloudinary.com/${cloudinaryUrl}/image/upload/${imagePublicId}`;
try {
const response = await fetch(cloudinaryApiUrl);
if (!response.ok) {
throw new Error(`Failed to fetch image. Status: ${response.status}`);
}
const imageData = await response.buffer();
return imageData;
} catch (error) {
console.error(`Error fetching image from Cloudinary: ${error.message}`);
throw error;
}
};
(async () => {
try {
const imageBuffer = await fetchImageFromCloudinary();
// Use the imageBuffer as needed, e.g., save to a file or send as a response
} catch (error) {
// Handle errors
}
})();