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

How to upload file in koa2? #952

Closed
SteveCruise opened this issue Mar 28, 2017 · 16 comments
Closed

How to upload file in koa2? #952

SteveCruise opened this issue Mar 28, 2017 · 16 comments

Comments

@SteveCruise
Copy link

SteveCruise commented Mar 28, 2017

And most important, with a callback when upload finish, like jquery-file-upload-middleware in express.
Getting params is also needed.

@carlisliu
Copy link

koa upload example

@SteveCruise
Copy link
Author

@carlisliu Thank you very much. But there should have a plugin to do that.

@fl0w
Copy link
Contributor

fl0w commented Mar 28, 2017

@SteveCruise
Copy link
Author

SteveCruise commented Mar 29, 2017

@fl0w koa-better-body is based on Formidable to deal with file upload. But Formidable is hard to use. jquery-file-upload-middleware is based on Formidable and makes it easy but it's only for express. Multer is not the right one.

@SteveCruise
Copy link
Author

Formidable is hard to deal with multiple upload.

@valVk
Copy link

valVk commented Mar 29, 2017

here is another promise based file uploader I'm using that in my project
https://github.com/m4nuC/async-busboy

@chanlito
Copy link

I use koa multer and works pretty well.

@SteveCruise
Copy link
Author

@BruceHem Yes, koa-multer is what I want, but it has little readme, I must read multer for express first.

@SteveCruise
Copy link
Author

SteveCruise commented Mar 30, 2017

I summarize the best choise of koa2 middleware here.
koa-router --- for router and work with koa-multer
koa-multer --- for upload file
koa-bodyparser --- for parse json and form
koa-send --- for download file
koa-session --- for session
koa-sslify --- forced change to https
koa-favicon
koa-logger
koa-static

@SteveCruise
Copy link
Author

@valVk Thank you very much.

@hirako2000
Copy link

I also had some struggle, thus wrote my own wrapper.

@crazyyi
Copy link

crazyyi commented Mar 19, 2018

@valVk Thanks this one is really easy to use.

@haifahrul
Copy link

@crazyyi Hi, what the best of it for upload file? What should I use?

@std4453
Copy link

std4453 commented Apr 13, 2019

What can I use to upload files directly as binary stream? Like with AWS S3 (and minio)?

@gideaoms
Copy link

gideaoms commented Nov 27, 2019

function store(ctx) {
    const form = new formidable.IncomingForm(...);
    form.parse(ctx.req, (err, fields, files) => {
        if (err) {
             ...
        }
        ...
    })
}

@nfantone
Copy link
Member

nfantone commented Dec 5, 2019

Exactly my question, @std4453. I was trying to scavenge around, searching for a solution - but failed to find a single mention to that use case. multipart/form-data encoding only makes sense in the context of HTTP forms.

The way I usually go about this is using raw-body myself in a custom middleware and messing with the request body as a Buffer.

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

No branches or pull requests