hono-file-upload: streaming file uploads for Hono #5570
Harshavardhan-Sondakar
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone! 👋
I made a small middleware for handling file uploads in Hono: hono-file-upload.
Why
c.req.parseBody()loads the whole file into memory before your handler runs. That's fine for small files, but large uploads use a lot of memory, and you can't stop a bad upload early.This middleware streams files while they arrive, so a big upload doesn't need a big amount of memory. Size limits are checked during the upload, so an oversized file is stopped right at the limit.
Example
Saving to disk or S3 / Cloudflare R2 is one option away:
Features
image/*c.var.uploadbased on the storage you useLinks
I'd really like feedback: bugs, missing features, or API ideas. Thanks! 🙏
All reactions