node.jsazuredockerkubernetesbuffer

'File is not defined' on file creation from zip buffer


Having issues with the generation of a file with new File([buffer]), in Node.js.

Got the error File is not defined.

Same code deployed twice:

package.json:

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

Dockerfile:

FROM node:18-alpine AS base
...

actions.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
  . . .
}

Solution

  • Apparently node:18 provides something to zip libraries that does not work very well with the buffer management. In fact, not only the problem came out with adm-zip, but with archiver as well.

    Once changed the Dockerfile base to node:20 the problem disappeared.

    It never manifested on the Azure App Service slot because it was already set to use Node 20 LTS.