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

Add ability to inject our custom multer instance to tsoa #1483

Open
2 of 4 tasks
lalchan opened this issue Sep 27, 2023 · 3 comments · May be fixed by #1638
Open
2 of 4 tasks

Add ability to inject our custom multer instance to tsoa #1483

lalchan opened this issue Sep 27, 2023 · 3 comments · May be fixed by #1638
Labels
good first issue This issue could be an easy PR for those looking to help contribute help wanted

Comments

@lalchan
Copy link

lalchan commented Sep 27, 2023

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

Ability to add my own custom multer instance to the tsoa instance as follow:

const multerInstance: Multer.Multer = multer({ ...your config here});

// it could be something like
RegisterRoutes(app, {
    multer: multerInstance
});

since above method seems out of scope for the RegisterRoutes function, we could do something like

RegisterMulter(multerInstance);
RegisterRoutes(app);

the above code would provide tsoa with the themulterInstance which it would use as it's multer instance instead of initializing it's own multer instance.

Current Behavior

Although we can customize the multerOpts using the tsoa.json, it seems to be incomplete as it is incapable of inserting storage engine to the multerOpts, rightfully so as it is a json file. This has caused some issue when i wanted to use multer-s3 as the storage engine for multer and also maintain the single truth in controller idea.

  • Using the @UploadedFile decorator will use the tsoa's multer instance, which cannot use multer-s3 is not a valid option.

  • Inserting my own multer middleware on top of the decorator will cause the request to fail as two multer instances(my multer-s3 multer instance and tsoa's multer instance) try to read file from the same request.

  • Only using the middleware will cause the swagger file to not have information about the file(although this can be mitigated by using this guide, I think this is a tedious and bandaid solution which doesn't follow the tsoa mantra of having single truth controller)

Possible Solution

See Expected Behaviour

P.S. I am new here, if I broke any rules, i apologize in advance.

@github-actions
Copy link

Hello there lalchan 👋

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

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

@WoH WoH added help wanted good first issue This issue could be an easy PR for those looking to help contribute labels Sep 28, 2023
@WoH
Copy link
Collaborator

WoH commented Sep 28, 2023

Would you like to submit a PR for this?
We can probably even deprecate the old way in this case, which is more flexible.
For convenience, the api should probably be RegisterRoutes(app, {multer}), I like that suggestion

@lalchan
Copy link
Author

lalchan commented Oct 3, 2023

Since I am new to this, I don't know what responsibilities submitting a PR include, will be submitting a PR as soon as I am available to work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue This issue could be an easy PR for those looking to help contribute help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants