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

Next.js中如何自定义可下载CSV文件的文件名?

修改CSV下载的自定义文件名

你只需要在Content-Disposition响应头中添加filename参数,就能指定自定义的下载文件名。修改后的代码如下:

const csv = converter.json2csv(data);
return new Response(csv, {
  headers: {
    'Content-type': 'text/csv',
    'Content-Disposition': 'attachment; filename="data.csv"',
  }
});

Content-Disposition的attachment值会告诉浏览器触发下载行为,而filename参数则明确指定了下载文件的名称,浏览器会直接使用这个名称作为保存的文件名。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 07:40:54