Struggling to figure out how to successfully upload a file to Cloudinary using fetch on my front-end. After consulting the documentation and various StackOverflow threads, I'm still facing a frustrating 400 error:
export async function uploadImageToCloudinary(file: File) {
const url = `https://api.cloudinary.com/v1_1/${cloudName}/upload`;
const fetched = await fetch(url, {
method: "post",
body: JSON.stringify({
file,
cloud_name: cloudName,
upload_preset: "unsigned",
}),
});
const parsed = await fetched.json()
console.log({
parsed // Error 400 - message: "Upload preset must be specified when using unsigned upload"
});
}
The error points to the upload preset not being specified, leading me to believe there's something amiss in the code above. The 'unsigned' upload preset has been set in my Cloudinary Settings as depicted below: https://i.sstatic.net/0H7dq.png