lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.33k stars 481 forks source link

Proposal/file upload configurations #1587

Open jackey8616 opened 4 months ago

jackey8616 commented 4 months ago

Currently in express/koa we have multer, hapi itself can handle file upload.

I've notice that we provides multerOptions in tsoa.json for preset a global multer instance. But such option is not event fit for hapi users.

When the #1483 gives the idea of custom instance of multer, I think its time to make something more 'general' for all users.

Here is my proposal:

  1. Stop using tsoa.json's multerOptions, we can mark it as deprecated, after keep supporting it for few versions then remove it.
  2. Define a global(for express/koa multer & hapi config) file upload config as RegisterRoutes parameter, allow users to provide it in there server.ts.
  3. There must be some needs on setting different upload destination path or file size limitation for endpoints, thus, we should introduce some kind of decorator like @UploadOptions takes more options and merge with default global configuration to provides different uploading setup for each endpoint.
jackey8616 commented 3 months ago

@WoH any suggestion?

WoH commented 2 months ago

Sorry, missed this so far. Btw, you can tag it as help wanted or pending feedback to avoid the bot.

Is it enough to provide this once for the entire app? I am worried the next follow up would be multer config for down to per Endpoint level.

jackey8616 commented 2 months ago

Sorry, missed this so far. Btw, you can tag it as help wanted or pending feedback to avoid the bot.

Is it enough to provide this once for the entire app? I am worried the next follow up would be multer config for down to per Endpoint level.

I think the global options we provides in RegisterRouter parameter could cover all.

midoelhawy commented 1 month ago

Hi @jackey8616,

As proposed in this pull request, you can provide your custom multer to RegisterRoutes, and tsoa will use it for file upload management in express and koa templates. Providing a multer instance is optional; by default, tsoa uses the default multer instance with the default configuration (or the configuration provided in tsoa.json).