File gets uploaded by always with an error : "Cannot read properties of undefined (reading 'write')"

I was spending some time trying to get file uploading done with NestJS/Fastify/Tus/Uppy. After some struggles I got it to work. Files get uploaded fine, but always returns the above error. So far I tried uploading very small files upto around 20MB. All gets uploaded and files are not corrupted either.

In dev tools what it shows is something like below

Seems like, it tries to upload a chunk, fails for some reason but manages to upload it again which goes fine.

The stack trace is below

"TypeError: Cannot read properties of undefined (reading ‘write’)\n at PatchHandler.send (D:\Projects\Streamline\streamline\node_modules\@tus\server\dist\handlers\PatchHandler.js:101:44)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async DashboardController.uploadChunk

my nestJS controller has two methods like below(Note I had to remove some NestJS specific syntax (using @) here because editor complained)

All(‘upload’)
async upload(Req() req:Request, Res() res:Response) {
return await this.tusService.handleTus(req, res);
}

All(‘upload/*’)
async uploadChunk(Req() req:Request, Res() res:Response) {
return await this.tusService.handleTus(req, res);
}

Having one method like upload/* doesn’t work. So i had to add /upload endpoint and /upload/* both. That is why I have two methods here.

What may be the issue?

Hi, are you using the latest version of @tus/server and your chosen store? I haven’t worked with NestJS, but in Fastify you have to pass the req.raw and res.raw, maybe you need to pass the underlying request/response object too?

Yes the versions are fine. it’s just that I did a major blunder. I forgot to send a proper response back after the file upload is finished. That was casing the problem. So i tapped into onUploadFinish and did something like below

        onUploadFinish: (req, res, upload) => {
            const savedFileName = this.copyFile(upload.id, upload.metadata.filename)
            return {
                res,
                headers: {
                    ### my data
                }
            };
        },.

This sorted the problem.