I'm having issues with svg files while running this code. The pngs and jpgs files are uploading to Cloudfare correctly, but when an svg file appears, it returns this error:
ERROR 9422: Decode error: image failed to be decoded: Uploaded image must have image/jpeg or image/png content type\n
Does anybody knows what I'm doing wrong? thanks
export default async (req: NextApiRequest, res: NextApiResponse) => {
const response = await axios.get(
"https://www.datocms-assets.com/45562/test-image.png",
{ responseType: "stream" }
);
const form = new FormData();
form.append("image", response.data, "test.png");
try {
const postRes = await axios.post(
`https://api.cloudflare.com/client/v4/accounts/my-id/images/v1`,
form,
{
headers: {
...form.getHeaders(),
Authorization: `Bearer my-api-key`,
},
}
);
console.info("response", postRes);
} catch (error) {
console.error("Error while uploading to cloudflare", error);
}
};