samchon / nestia

NestJS Helper Libraries + TypeScript OpenAPI generator
https://nestia.io/
MIT License
1.76k stars 91 forks source link

Add option to pass `multer` options to Multipart uploads #819

Open fgodino-milu opened 6 months ago

fgodino-milu commented 6 months ago

Feature Request

Problem

Currently, @TypedFormData.Body() uses multer to read and store file uploads but it doesn't support passing options to the multer singleton.

I am trying to use DiskStorage to store uploads but multer uses MemoryStorage by default.

Additionally, the type of files within @TypedFormData.Body() is File, which hides a lot of the information in Express.Multer.File types and it's not supported in Node versions prior two 20.

Request

  1. Add option to be able to pass multer options to multipart uploads
  2. Use Express.Multer.File type instead of File for files (see https://expressjs.com/en/resources/middleware/multer.html#api)

Thanks!

samchon commented 5 months ago

As I also have to consider the fastify case, supporting express-multer options are not easy problem.

Will you suggest or send a PR that can make both express and fastify compatible?

fgodino-milu commented 5 months ago

Hi @samchon

I found this package https://www.npmjs.com/package/fastify-multer, which is a port of express-multer. It supports the same options and it outputs the same output types.

I think using this library would simplify it a bit.

Let me know what you think

samchon commented 5 months ago

Seems good. What about challenge a PR in here code?

https://github.com/samchon/nestia/blob/master/packages/core/src/decorators/TypedFormData.ts

fgodino-milu commented 1 month ago

@samchon what do you think about the PR?

samchon commented 1 month ago

I looked your PR. Changing dependent library of @TypedFormData() in fastify requires major level update.

As I'm not developing the multipart/form-data type in the backend development, so I can't sure that fastify-multer is enough valuable for processing the major version level update. I hope many other users' opinions of this issue, but as you know, nestia users are not such a lot.

Therefore, consider the aspect and tell me your opinion about this thing. If you still think that the major version update is valuable, I'll re-check it when typia v7 and nestia v4 major updates.

fgodino-milu commented 1 month ago

I think this would be a great addition since the multipart uploads are a big part in some projects that heavily depend on multimedia files. The other solution that would not require a breaking change is to have different options in the @TypedFormData decorator for fastify and express. I believe though, that the unification simplifies things