尝试使用 axios 将 svg 图像上传到 Cloudflare 时遇到问题

2023-12-15

我在运行此代码时遇到 svg 文件问题。 png 和 jpgs 文件正确上传到 Cloudfare,但是当出现 svg 文件时,它返回此错误:

错误 9422: 解码错误: 图像解码失败: 上传的图像必须具有 image/jpeg 或 image/png 内容类型\n

有人知道我做错了什么吗?谢谢

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);
  }
};

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

尝试使用 axios 将 svg 图像上传到 Cloudflare 时遇到问题 的相关文章

随机推荐