I have successfully implemented a function in my React Native application to upload images to Cloudinary. Now, I am trying to modify the function to upload audio files as well. Despite specifying the "resource_type" parameter as "raw", "video", or "auto", I keep encountering the error [Error : Invalid image file].
const CLOUDINARY_UPLOAD_URL = `https://api.cloudinary.com/v1_1/${CLOUD_NAME}/image/upload`;
// This function takes a base64 audio file as an argument
export const uploadAudio = async (
audio: string
): Promise<UploadImageResult> => {
// A function that requests a signature from my API to load the resource
const {
signature,
timestamp,
upload_preset,
} = await getCloudinarySignature();
const formData = new FormData();
formData.append("file", audio);
formData.append("resource_type", "raw");
formData.append("signature", signature);
formData.append("timestamp", timestamp);
formData.append("upload_preset", upload_preset);
formData.append("api_key", API_KEY);
const res = await fetch(CLOUDINARY_UPLOAD_URL, {
method: "POST",
body: formData,
});
const data = await res.json();
if (!res.ok || !data.secure_url) throw new Error(data.error.message);
return {
url: data.secure_url,
asset_id: data.asset_id,
public_id: data.public_id,
};
};
Could someone please point out where I might be going wrong? Thank you.