【问题标题】:Fetch blob in backend and send to front end在后端获取 blob 并发送到前端
【发布时间】:2025-12-25 04:25:17
【问题描述】:

我正在尝试以媒体/gif 的形式获取 blob,然后立即将其发送到我的前端。出于安全和缓存目的,我需要首先在我的后端(Vercel 中的无服务器功能)中获取它。当直接从 Postman 和我的前端中的源 URL 获取 blob/图像时,一切正常,但是当第一次在我的后端获取它然后将它传递给 Postman 和我的前端时它不起作用。

我的后端代码:

export default async (_: NowRequest, response: NowResponse) => {
  const res = await Axios.get(
    "{BLOB_URL}"
  );
  response.setHeader("Content-Type", "media/gif");

  return response.status(200).send(res.data);
};

我错过了什么?

【问题讨论】:

    标签: blob gif serverless vercel


    【解决方案1】:

    通过添加以下内容解决了它:

    export default async (_: NowRequest, response: NowResponse) => {
    
      const res = await Axios.get(
        "{BLOB_URL}",
         { responseType: "arraybuffer" } <--- ADDED THIS
      );
    
      response.setHeader("Content-Type", "media/gif");
    
      return response.status(200).send(res.data);
    };
    

    【讨论】: