You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vercel部署项目后动态GIF横幅无法正常生成求助

Vercel部署后动态GIF横幅生成失败:Blob体积过小且Content-Type异常

我刚完成第一个基于JavaScript后端+React前端的项目,功能是生成可自定义颜色、文字、字体的个性化动态GIF横幅。本地运行时所有功能完全正常,但部署到Vercel后,动态GIF横幅无法正确生成。经过多日排查,发现两个关键异常:

  • 后端生成的Blob体积仅约600字节,远小于本地环境下的数值
  • Blob的Content-Type为text/html,而非本地环境的image/gif

我已经检查并确认以下配置均正确设置:

  1. CORS配置:
app.use(
  cors({
    origin: "*",
    methods: "GET",
    allowedHeaders: ["Content-Type", "Authorization"],
  })
);
  1. Content-Type设置:
res.set("Content-Type", "image/gif");
  1. 后端核心接口代码:
app.get("/generate-banner", async (req, res) => {

  // Default values
  const text = req.query.text || "This is your banner";
  const textColor = req.query.textColor || "FFFFFF";
  const bgColor = req.query.bgColor || "000000";
  const font = req.query.font || "Arial";
  const fontSize = req.query.fontSize || "18";

  // Generates the GIF
  const gifBuffer = createBannerGif(text, textColor, bgColor, font, fontSize);
  (...)

  // Returns the GIF
  return gifBuffer;
};
  1. 前端请求代码:
fetch(`https://banderole.vercel.app/generate-banner?text=${text}&textColor=${strippedTextColor}&bgColor=${strippedBgColor}&font=${selectedFont}&fontSize=${selectedFontSize}`)
  1. 本地环境中所有功能均正常运行

若有疑问,欢迎随时提出!

内容的提问来源于stack exchange,提问作者Kanakito

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 16:03:28