Search code examples
node.jstypescriptexpressmultertsoa

tsoa-swagger: file parameter is always undefined in upload


I have a problem with Tsoa nodejs File upload

I wrote the method based on the tsoa documentation but the output varible is always undefined

This is my method

enter image description here

  @Post('/uploadNewExporterTemplate')
  public async uploadNewExporterTemplate(
    @Query() templateName: string,
    @Query() unit: string,
    @Query() testWith: string,
    @UploadedFile() file: Express.Multer.File,
  )  {

    const mul = multer()

    
    console.log(file,unit,testWith);
    
    return {stat:"Ok",ss:templateName}
  }

And this is the swagger result

enter image description here

and finally this the debug result

enter image description here

enter image description here


Solution

  • I'm not sure why but according to provided screenshot of Swagger UI, your file field is in Request body section, but the rest of the fields are in Parameters section. As far as I know, all fields should be in one section called Request body or Parameters.

    I suggest you try changing Query() to FormField() accordingly to tsoa docs.

    If above does not help, I have a few suggestions:

    1. Check what's inside generated routes file. There should be some multer logic added by tsoa.
    2. Compare your generated swagger.json with the one provided in the Swagger example.
    3. Try running the request outside Swagger UI (e.g.: Postman) or use DevTools to check what is Swagger UI does under the hood (Network tab, check the requests).