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

Proposal/file upload configurations #1587

Open
jackey8616 opened this issue Mar 13, 2024 · 9 comments
Open

Proposal/file upload configurations #1587

jackey8616 opened this issue Mar 13, 2024 · 9 comments

Comments

@jackey8616
Copy link
Collaborator

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
Copy link
Collaborator Author

@WoH any suggestion?

@github-actions github-actions bot added the Stale label Apr 19, 2024
@jackey8616 jackey8616 removed the Stale label Apr 25, 2024
Repository owner deleted a comment from github-actions bot Apr 25, 2024
@WoH WoH reopened this Apr 25, 2024
@WoH
Copy link
Collaborator

WoH commented Apr 25, 2024

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
Copy link
Collaborator Author

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
Copy link

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).

@midoelhawy
Copy link

it's already supported in v6.4.0
you can inject your custom multer instance in RegisterRoutes
exmaple:

RegisterRoutes(router, {
  multer: multer({
    limits: {
      fieldNameSize: 120,
    },
  }),
});

@jackey8616
Copy link
Collaborator Author

@midoelhawy
thanks for your excellent work!
I think we can move on to endpoint file size restriction / configurations.

@jackey8616
Copy link
Collaborator Author

@WoH
I will submit a PR mark config multer options deprecated and add some warning.
We can discuss when to totally remove the code snippets.

In the meantime, I will working on another PR enhance the @uploadedfile decorator with multer options in order to make specific restriction on each file and endpoint.

@ashoktamang
Copy link

it's already supported in v6.4.0
you can inject your custom multer instance in RegisterRoutes
exmaple:

RegisterRoutes(router, {
  multer: multer({
    limits: {
      fieldNameSize: 120,
    },
  }),
});

Isn't routes.ts file auto-generated? Where should this logic be implemented?

@midoelhawy
Copy link

midoelhawy commented Nov 9, 2024

Hi @ashoktamang,

You need to register the autogenerated route in your Express app server using the RegisterRoutes function. This function now accepts additional parameters beyond just app, your Express instance. You can also pass a second parameter, opts, which can include { multer: multer({ limits: { fileSize: 31457280, // other config } }) }.

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

4 participants