TypeScript and TSOA : Error Code LIMIT_UNEXPECTED_FILE with multiple @UploadedFile

1.2k Views Asked by At

I build a Rest API using typescript and TSOA with Express. In a route, I try to receive multiple formfields (using the decorator @FormField) and multiple file fields (using the e decorator @UploadedFile).

see official link : https://tsoa-community.github.io/docs/file-upload.html

When I define only one file, the route is working well, but when I add a second file field, Multer complains with the error :

MulterError: Unexpected field
    at wrappedFileFilter (*******\node_modules\multer\index.js:40:19)
    at Busboy.<anonymous> (*******\node_modules\multer\lib\make-middleware.js:115:
7)
    at Busboy.emit (node:events:526:28)
    at Busboy.emit (node:domain:475:12)
    at Busboy.emit (*******node_modules\busboy\lib\main.js:38:33)
    at PartStream.<anonymous> (*******\node_modules\busboy\lib\types\multipart.js:
213:13)
    at PartStream.emit (node:events:526:28)
    at PartStream.emit (node:domain:475:12)
    at HeaderParser.<anonymous> (*******\node_modules\dicer\lib\Dicer.js:51:16)   
    at HeaderParser.emit (node:events:526:28) {
  code: 'LIMIT_UNEXPECTED_FILE',
  field: 'banner',
  storageErrors: []
}

this is the code of the controller:

 @Post('')
    public async create(
        @Request() request: any,
        @FormField() label: string,
        @FormField() email: string,
        @UploadedFile('logo') logo?: Express.Multer.File,
        @UploadedFile('banner') banner?: Express.Multer.File,
    ): Promise<ResponseType> {
        try {
            const ns = await this.service.create({
                    label,
                    email,
                 },
                request.user,
            );
            return { data: ns, success: true, detail: 'success' };
        } catch (e: any) {
            console.error(e);
            this.setStatus(400);
            return { detail: 'Validation Failed for Request Data : ' + e.message, success: false };
        }
    }

I think it is probably an error of Multer expecting only one file in the Request. So how can I specify that there is two files in the request with different fields using TSOA ?

1

There are 1 best solutions below

0
On

did not receive an answer even though i posted an issue in github, sadly time to move away from TSOA.