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

File parameter always undefined #772

Closed
ghost opened this issue Feb 27, 2020 · 5 comments
Closed

File parameter always undefined #772

ghost opened this issue Feb 27, 2020 · 5 comments

Comments

@ghost
Copy link

ghost commented Feb 27, 2020

Hello, I'm having trouble getting the a file from a request. It's very similar (if not the same) as this one: Gitter @trashtatur's problem

The function that retrieves the file (set in a controller)

  @Post("/")
  @Status(201)
  @Description("Send midia.")
  @MulterOptions({dest: `${process.cwd()}/.tmp`})
  async upload(@MultipartFile("midia") midia: Express.Multer.File) {
    console.log(midia); // undefined
    
  }

My Server settings:

@ServerSettings({
  rootDir,
  acceptMimes: ["application/json", "multipart/form-data"],
  httpsPort: isPRD,
  // Versioning
  mount: {
    "/v1": [
      `${rootDir}/controllers/**/**Ctrl.ts`
    ]
  },
  componentsScan: [
    `${rootDir}/services/*.ts`,
    `${rootDir}/repositories/*.ts`,
    `${rootDir}/protocols/*.ts`
  ],
    },
  ],
  // Docs
  swagger: [
    {
      path: "/v1/docs",
      doc: "api-v1"
    },
  ]
})
export class Server extends ServerLoader {
  /**
   * This method let you configure the express middleware required by your application to works.
   * @returns {Server}
   */
  public $beforeRoutesInit(): void | Promise<any> {
    this
      .use(GlobalAcceptMimesMiddleware)
      .use(cookieParser())
      .use(compress({}))
      .use(methodOverride())
      .use(bodyParser.json())
      .use(bodyParser.urlencoded({
        extended: true
      }));
  }
}

This is the call from Swagger (supposedly a FormData):
image

From Swagger UI ("Error: Bad Request" is mine, I'm checking in the code with if (!midia) throw...)
image

The CURL

curl -X POST "http://localhost:8080/v1/envios" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "midia=@Malganis.jpg;type=image/jpeg"

As you can see the boundary is beign set:
"Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryw9RTs1tnj4g5h2su"

This is the original code, I've removed to isolate the error:
image

I don't see anything that have much of diference from the example project

These are the dependencies:

"@tsed/common": "^5.44.0",
"@tsed/core": "^5.44.0",
"@tsed/di": "^5.44.0",
"@tsed/multipartfiles": "^5.44.0",
"@tsed/swagger": "^5.44.0",
"@tsed/testing": "^5.44.0",
"@tsed/typeorm": "^5.44.0",
"multer": "^1.4.2",

λ node -v → v13.8.0

Side note: in docs about getting start with multer the command to install the package npm install --save @tsed/multer, doesn't work because it isn't found.

@ghost ghost added the ❔ question label Feb 27, 2020
@ghost ghost assigned Romakita Feb 27, 2020
@ghost ghost changed the title File parameter undefined File parameter always undefined Feb 27, 2020
@ghost
Copy link
Author

ghost commented Feb 27, 2020

Tried from a clean install (rm node_modules), didn't work either.

@ghost
Copy link
Author

ghost commented Feb 27, 2020

image
The file is uploaded to .tmp folder

@ghost
Copy link
Author

ghost commented Feb 28, 2020

Copying and pasting from the example also returns undefined:
image

@ghost
Copy link
Author

ghost commented Feb 28, 2020

I can capture it from @Req() decorator, from files:

image

But it just breaks the purpose of @MultipartFile and the elgancy for me.

@Romakita Romakita added this to the BACKLOG milestone Feb 28, 2020
@Romakita
Copy link
Collaborator

🎉 This issue has been resolved in version 5.44.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

No branches or pull requests

1 participant