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

Error from sending empty body multipart/form-data #780

Closed
misonomikadev opened this issue Aug 15, 2024 · 5 comments
Closed

Error from sending empty body multipart/form-data #780

misonomikadev opened this issue Aug 15, 2024 · 5 comments
Assignees
Labels
bug Something isn't working review Waiting for issue reporter approval

Comments

@misonomikadev
Copy link

What version of Elysia is running?

1.1.6

What platform is your computer?

Linux 6.5.0-45-generic x86_64 x86_64

What steps can reproduce the bug?

Send only file is normal
Send only "name" field is normal
Send both "file" and "name" is normal
but when nothing in body it throw "Failed to parse body"

import { Elysia, t } from 'elysia'

const app = new Elysia()

app.post('/', ({ body }) => {
    console.log(body)

    return { ok: true } 
}, {
    type: 'multipart/form-data',
    body: t.Object({
        file: t.Optional(t.File()),
        name: t.Optional(t.String())
    })
})

app.listen(5000, (server) => {
    console.log(`> App is listening at: ${server.url.origin}`)
})

What is the expected behavior?

body is {}

What do you see instead?

"Failed to parse body" in response

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

Yes

@misonomikadev misonomikadev added the bug Something isn't working label Aug 15, 2024
@misonomikadev misonomikadev changed the title Error from sending non-required file field multipart/form-data Error from sending empty body multipart/form-data Aug 15, 2024
@JohnRoseDev
Copy link

Could be related to #563

@SaltyAom
Copy link
Member

Should have been fixed with 2085673, published under 1.1.8.

Let me know updating fix your issue or not, thanks.

@SaltyAom SaltyAom added the review Waiting for issue reporter approval label Aug 27, 2024
@SaltyAom SaltyAom self-assigned this Aug 27, 2024
@misonomikadev
Copy link
Author

@SaltyAom It still not resolve my issue. I try to delete node_modules and reinstall 1.1.8 again but still have "Failed to parse body".

@SaltyAom
Copy link
Member

@misonomikadev I think you need to make sure that body is optional as well.

Something like this

app.post('/', ({ body }) => {
    console.log(body)

    return { ok: true } 
}, {
    type: 'multipart/form-data',
    body: t.Optional(t.Object({
        file: t.Optional(t.File()),
        name: t.Optional(t.String())
    }))
})

@misonomikadev
Copy link
Author

Hmmmmm okay seem work to me, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working review Waiting for issue reporter approval
Projects
None yet
Development

No branches or pull requests

3 participants