appendFile nodejs 在生产中无法正常工作

appendFile nodejs not working properly in production

我正在使用块执行上传功能,在本地它工作正常,但是当我开始生产时,按 appendFile 完全分组的文件不完整。

代码工作如下,在前端我将文件分成1mb块,用函数命名它是一个唯一的名称,将它发送到后端并在具有该名称的文件上执行appendFile

request.on("data", (part) => {
    chunk.push(part);
}).on("end", async () => {
    const firstChunk = chunkId === 0;
    const lastChunk = (chunkId) === (chunksQuantity) -1;
    const completedChunk = Buffer.concat(chunk);
    
    if (firstChunk && existsSync(`${__dirname}/../../uploads/videos/${fileName}`)) {
      unlinkSync(`${__dirname}/../../uploads/videos/${fileName}`);
    }

    appendFile(`${__dirname}/../../uploads/videos/${fileName}`, completedChunk, async (err)=> {
      if(err) throw err;
      if(lastChunk) {
        //I upload the video to s3 and follow our internal flow
      }
    });

I opened the files with a text editor to see the size of the writing and doing the math really missing 1 piece of 1mb approximately

我不明白发生了什么,在我们的生产环境中,我们使用 kubernetes 并通过它来平衡请求,因为我们发送了最大 5mb 的缓冲区片段,当我们挂载文件时,这些片段是在不同的 pods.

我们将请求的传输方式更改为流式传输,一切顺利。