Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: add per route busboy configuration #580

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
Loading
from

Conversation

grigoran
Copy link

@grigoran grigoran commented May 13, 2025

There was a need to restrict the file size in each route when used alongside attachFieldsToBody. These changes will enable route-specific busboy configuration.
Example

fastify.post('/', {
    schema: {
        consumes: ['multipart/form-data'],
        body: Type.Object({
            // file: {isFile: true} as unknown as TSchema
            file: Type.Unsafe<{ toBuffer: () => Promise<Buffer> }>({ isFile: true })
        }),
        response: {
            200: Type.Object({
                ok: Type.Boolean()
            })
        }
    },
    config: {
        multipart_options: {
            limits: {
                fileSize: 1024*1024*2 // 2MB
            }
        }
    }
}, async (req, rep) => {
    const buf = req.body.file.toBuffer();
    return { ok: true }
})

Checklist

Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some unit test?

index.js Outdated Show resolved Hide resolved
@grigoran
Copy link
Author

Thank you! Done

@grigoran grigoran requested a review from Eomm May 14, 2025 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.