In the context of using the Cloudinary API, I need to send data formatted as multipart/form-data
. However, I’m in a situation where FormData is not accessible. What alternatives can I consider for achieving that? Here’s a basic example of what I would use if FormData were available:
const dataToSend = new FormData();
dataToSend.append('image', assetUrl);
dataToSend.append('preset', CLOUDINARY_UNSIGNED_UPLOAD_PRESET);
dataToSend.append('name', CLOUDINARY_CLOUD_NAME);
console.log(`Starting upload (id: ${id}) to Cloudinary`, CLOUDINARY_UPLOAD_URL, dataToSend);
const result = await fetch(CLOUDINARY_UPLOAD_URL, {
method: 'POST',
body: dataToSend,
});
I’ve experimented with various methods, but it appears that the Cloudinary API is quite particular and only accepts data sent in the multipart/form-data
format.