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

feat(platform): add fastify-multipart support for fastify platform #6935

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maronfranc
Copy link

add FileInterceptor, FilesInterceptor, AnyFilesInterceptor and
FileFieldsInterceptor for platform-fastify

closes #6894

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Currently file upload interceptor is an important feature that is missing in @nestjs/platform-fastify.

Issue Number: N/A

What is the new behavior?

FileInterceptor(s)

Behave as platform-express.

MultipartWrapper

A fastify-multipart wrapper that is responsible to handle file streams and return theses streams result to interceptor.

  • It expands fastify-multipart options object adding fileFilter:
    • this filter acts in a similar ways as multer fileFilter
  • It is responsable consume fileStream:
    • add size and originalname to file
    • if options.dest is truthy:
      • recursively write folder and then file
      • add path and destination to file object
    • else skip fileStream consumption.
  • It handles fastify-multipart req.files() object differently in each method:
    • files() and any() return array of files
    • fileFields() return object with array of files

filterAsyncGenerator

An utils function that filters AsyncGenerator validating options.fileFilter callback conditions before the write iteration begins.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

I hope this pull request help us find the best solution for platform-fastify file upload interceptor.

add FileInterceptor, FilesInterceptor, AnyFilesInterceptor and
FileFieldsInterceptor for platform-fastify

closes nestjs#6894
@coveralls
Copy link

Pull Request Test Coverage Report for Build a3454d6e-4d99-46cf-8ab9-60f563025985

  • 239 of 243 (98.35%) changed or added relevant lines in 13 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 94.782%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/platform-fastify/multipart/interceptors/any-files.interceptor.ts 13 14 92.86%
packages/platform-fastify/multipart/interceptors/file.interceptor.ts 12 13 92.31%
packages/platform-fastify/multipart/multipart/multipart-wrapper.ts 146 147 99.32%
packages/platform-fastify/multipart/multipart/multipart.utils.ts 11 12 91.67%
Totals Coverage Status
Change from base Build 7b78aa8f-2ae9-4f8e-9a68-151f2b96d8c7: 0.2%
Covered Lines: 5358
Relevant Lines: 5653

💛 - Coveralls

@TheNoim
Copy link
Contributor

TheNoim commented Apr 26, 2021

This would be awesome. Does this support the @UploadedFile() param decorator? Can't find it in the pr.

@maronfranc
Copy link
Author

This would be awesome. Does this support the @UploadedFile() param decorator? Can't find it in the pr.

Yes, it does support @UploadedFile() and @UploadedFiles(). Here you can find a sample code for this feature.

@andreferraro
Copy link

Hi guys, is there anything new? What should we do to merge this feature?

@m-risto
Copy link

m-risto commented Sep 16, 2021

Waiting for this so long. We want to move to fastify, this is a blocker. We would be very happy if this is merged.

@kscerbiakas
Copy link

@micalevisk Hi, I see you approved PR. Does this mean that PR will get merged with next release?

@micalevisk
Copy link
Member

@kscerbiakas

Does this mean that PR will get merged with next release?

Unfortunately, no. I'm not a member of Nestjs's core team. It just means that I liked the proposed solution and tested it myself. It doesn't mean there is no room for improvement, of course.

I do this from time to time with old PRs that I think are good to merge. Just to ping the core team (in some sort) :)

@kscerbiakas
Copy link

Any status update on this PR?

@yeongjet
Copy link

yeongjet commented Dec 17, 2021

You may interested: nest-fastify-multer, it works fine in my project.

@vytautas-pranskunas-
Copy link

any progress on this?

@DamianGlowala
Copy link

@kamilmysliwiec, any chances to include this PR in Nest v9.0.0 release?

@EvilCheetah
Copy link

@kamilmysliwiec
Any updates on this issue?

@PringlePot
Copy link

Love how there are 2 pull requests fixing this issue, however it is still not possible to implement this on the nestjs standards.

@jackgdll
Copy link

jackgdll commented Feb 17, 2023

Any new updates for this PR? It seems that a lot of people have been asking for this for a long time and it makes sense for better feature parity between the express and fastify platforms.
Is there a problem with the proposed solutions that I'm not aware of?

@SzymonGonet
Copy link

Any updates? @kamilmysliwiec

@xegulon
Copy link

xegulon commented Nov 6, 2023

What's blocking the PR to be merged @kamilmysliwiec @jmcdo29?

@anton-liam
Copy link

any update?

@kamilmysliwiec

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

Successfully merging this pull request may close these issues.

[Feature] fastify-multipart interceptors