CNode

node返回zip文件损坏

问答
Bbinyellow发布于7 年前最后回复7 年前1 回复4602 浏览0 收藏

问题描述: 用koa返回文件流,设置了"Content-Type": "application/zip"和 "application/octet-stream",返回文件没问题,但是返回.zip文件,前端下载后就损坏了,请问是什么问题 截图和代码如下 image.png async function generator(ctx, next) { const zipDirPath = path.join(__dirname, "../template/list/"); const fileName = 'index.zip'; const zipPath = zipDirPath + fileName; ctx.set({ "Content-Type": "application/zip", "Content-Disposition": attachment; filename=${fileName} }); ctx.body = await fs.createReadStream(zipPath); }

查看回复

回复 (1)

O
ounana#1·7 年前

请问 你压缩了吗

参与回复
登录后即可参与回复。登录