I'm using the images api to upload a bunch of images to Cloudflare. But I'm having trouble with the svgs ones... does anybody knows if Cloudflare supports them? I'm not finding any docs for that. Thanks!
I'm getting this error when running the code. 'ERROR 9422: Decode error: image failed to be decoded: Uploaded image must have image/jpeg or image/png content type\n'
My code:
let imageUrl = "";
// We get the datoCMS image upload id and fetch the url, then we post it in cloudfare
const image = await datoManagementPrimaryEnvironment.upload.find(uploadId);
const fileName = title ? title : image.basename ? image.basename : "image";
const response = await axios.get(image.url, { responseType: "stream" });
const form = new FormData();
// Pass image stream from response directly to form
form.append("file", response.data, `${fileName}`);
try {
const postRes = await axios
.post(
`https://api.cloudflare.com/client/v4/accounts/${cloudfareId}/images/v1`,
form,
{
headers: {
...form.getHeaders(),
Authorization: `Bearer ${cloudfareApiKey}`,
},
}
)
.then((fetchRes) => {
return (imageUrl = fetchRes.data.result.variants[0]);
});
return postRes;
} catch (error) {
console.error("Error while uploading to cloudflare", error);
} finally {
return imageUrl;
}