Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'length') with @UploadedFile #1580

Closed
2 of 4 tasks
markusdostal opened this issue Mar 11, 2024 · 1 comment · Fixed by #1583
Closed
2 of 4 tasks

Cannot read properties of undefined (reading 'length') with @UploadedFile #1580

markusdostal opened this issue Mar 11, 2024 · 1 comment · Fixed by #1583

Comments

@markusdostal
Copy link

markusdostal commented Mar 11, 2024

Sorting

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

Current Behavior

In an express application I have an endpoint which expects form-data. Text fields and file fields are mixed.
Whenever I try to send a request to this endpoint I get the error in "expressTemplateService" which is shown below. This error has first shown up in version 6.1.0. Older releases of tsoa worked as expected.

grafik

As is shown below, i have a file with the name "avatar":

grafik

But to access the requestedFiles "username" is used, which is the name of a text field. This is why "fileArgs" is undefined and why the check of the length fails.

grafik

Possible Solution

Steps to Reproduce

Add an Endpoint like this:

@Put()
  public async updateUser(
    @FormField("username") username: string,
    @UploadedFile("avatar") avatar: File
  ): Promise<void> {
    console.log("username", username);
    console.log("avatar", avatar);
    return;
  }

an send a request to this endpoint with Postman

This should generate the following console output:

Example app listening at http://localhost:3000
TypeError: Cannot read properties of undefined (reading 'length')
    at D:\Tests\tsoa_test\node_modules\@tsoa\runtime\dist\routeGeneration\templates\express\expressTemplateService.js:59:41
    at Array.map (<anonymous>)
    at ExpressTemplateService.getValidatedArgs (D:\Tests\tsoa_test\node_modules\@tsoa\runtime\dist\routeGeneration\templates\express\expressTemplateService.js:32:44)
    at UsersController_updateUser (D:\Tests\tsoa_test\build\build\routes.js:99:45)
    at Layer.handle [as handle_request] (D:\Tests\tsoa_test\node_modules\express\lib\router\layer.js:95:5)
    at next (D:\Tests\tsoa_test\node_modules\express\lib\router\route.js:149:13)
    at done (D:\Tests\tsoa_test\node_modules\multer\lib\make-middleware.js:45:7)
    at indicateDone (D:\Tests\tsoa_test\node_modules\multer\lib\make-middleware.js:49:68)
    at Multipart.<anonymous> (D:\Tests\tsoa_test\node_modules\multer\lib\make-middleware.js:166:7)
    at Multipart.emit (node:events:518:28)

Context (Environment)

Version of the library: @tsoa/runtime: ^6.1.1 / @tsoa/cli: ^6.1.1
Version of NodeJS: v20.11.1

  • Confirm you were using yarn not npm: [ ]

Detailed Description

Breaking change?

Copy link

Hello there markusdostal 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant