K8S - node.js - 从 zip 缓冲区创建文件时“文件未定义”

问题描述 投票:0回答:1

在 Node.js 中使用

new File([buffer])
生成文件时遇到问题。

出现错误

File is not defined

相同的代码部署两次:

  • 在 AKS pod 中

    • dockerfile 使用节点:18-alpine
    • 错误存在
  • 在 Azure 应用服务插槽中

    • 设置:节点 20 LTS
    • 错误不存在
package.json:

"dependencies": { ... "adm-zip": "^0.5.16", ... }
Dockerfile

FROM node:18-alpine AS base ...
动作.ts

const async myfun = upload(_:any, formData: FormData) => { const id = formData.get('id') const pdfs = formData.get('pdfs') as File[] const zip = new AdmZip() for await (const pdf of pdfs) { const zip.addFile(pdf.name, Buffer.from(await pdf.arrayBuffer())) } const zipBuffer = finalZip.toBuffer() const zipFile = new File([zipBuffer], id+'.zip', {type: "application/zip"}) //<---- error is thrown here . . . }
    
node.js azure docker kubernetes buffer
1个回答
0
投票
把这个留给有同样问题的人。

显然

node:18

 提供了一些与缓冲区管理不能很好配合的压缩库。事实上,不仅
adm-zip
有问题,
archiver
也有问题。

一旦将 dockerfile 库更改为

node:20

,问题就消失了。

它从未出现在 Azure 应用服务插槽上,因为它已设置为使用 Node 20 LTS。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.