'Nest.JS/Multer: UploadedFile undefined

I've got some strange problem here: I've setup file upload just like in the nest.js tutorials. On my machine (Windows 10) everything works fine but when I deploy the project on my dev server everything builds just fine, but when I try to upload a file the uploadedFile parameter is undefined. I've checked the request and found out that in the rawHeaders section my submitted data is missing. On my machine the api's request object contains this under rawHeaders:

    'User-Agent',
    'PostmanRuntime/7.29.0',
    ...
    'Content-Type',
    'multipart/form-data; boundary=--------------------------584912758523510642468219',
    'Content-Length',
    '312047'

On my dev server, that same request suddenly only contains this data:

    'User-Agent',
    'PostmanRuntime/7.29.0',
    ...
    'Content-Length',
    '0'

I guess that is the reason why my file variable is undefined, but why? Any idea how this could ever happen? I'm a bit lost here... I've already deleted my node_modules and rebuilt it, but no success. Versions of npm and node are equal on both systems.

My code is currently just this:

@Post('upload')
@UseInterceptors(FileInterceptor('file'))
uploadFile(@Req() req : Request, @UploadedFile() file: Express.Multer.File) {
  console.log(req);
  console.log(file);
}

Greets, Bruno



Solution 1:[1]

I've spent whole day today to find the solution for this bug. And I found that another small library can close this issue for us.

Enjoy! nestjs-form-data

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1