【发布时间】:2021-08-07 15:22:09
【问题描述】:
我有一个 NextJS 应用程序,我必须在其中生成大量 QR 码,一次 300,400,500 个。我想把它们放在一个 zip 中,让用户下载它们。这是使用 archiver 库将代码放入 zip 的代码:
const archive = archiver.create("zip", {});
let index = 1;
for (const code of codes) {
// @ts-expect-error
const qrCode = new QRCodeStyling({
nodeCanvas: canvas,
width: 300,
height: 300,
data: code.url
});
archive.append(
await qrCode.download({
name: "testName",
extension: "png",
skipDownload: true,
buffer: true,
}),
{
name: `${code.name}-${index}.png`,
},
);
index++;
}
console.log("before finalizing");
await archive.finalize();
console.log("after finalizing");
return archive;
请求在本地机器上大约需要 10 秒,而在生产环境中,它每次都会超时。该程序有时甚至没有响应,它只是挂在before finalizing..
这就是我将代码发送到前端的方式:
res.setHeader("Content-Disposition", "attachment");
return res.status(200).send(await exportCodes());
请注意,这些 zip 文件通常在 3-5mb 左右,所以我认为大小应该不是问题
【问题讨论】:
-
网站在生产中给你的错误是什么?
-
@Mallard 'Task timed out after 10.01 seconds',网站托管在 Vercel 平台上。
标签: javascript node.js typescript next.js