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 read file from request? #434

Open
ozgreat opened this issue Apr 26, 2020 · 4 comments
Open

How to read file from request? #434

ozgreat opened this issue Apr 26, 2020 · 4 comments

Comments

@ozgreat
Copy link

@ozgreat ozgreat commented Apr 26, 2020

I wanna read a file from req, how can I do it? I don't wanna use micro-upload

@OlliV
Copy link

@OlliV OlliV commented Apr 27, 2020

Just read or also write it to somewhere?
There are various ways to read the body. For small files you could just do:

const {buffer} = require('micro');
...
const data = await buffer(req);
@ozgreat
Copy link
Author

@ozgreat ozgreat commented May 1, 2020

Just read or also write it to somewhere?
There are various ways to read the body. For small files you could just do:

const {buffer} = require('micro');
...
const data = await buffer(req);

I wanna upload them to s3, but when I try to fs.writeFile(fileName, buf, err => console.log(err)) file is broken

@rishabhjaishwal
Copy link

@rishabhjaishwal rishabhjaishwal commented Aug 21, 2020

Just want to know that anyone contribute to this repo

@AubreyHewes
Copy link

@AubreyHewes AubreyHewes commented Oct 8, 2020

@ozgreat Micro is designed to be minimal and simplistic. You either need to write your own modules or use community modules.

You mention you do not want to use micro-upload ? You do not mention why you do not want to use this. Maybe as you expect a posted binary file?

I know that the currently published micro-upload is old and fails npm audits. The repo has a dependabot branch that alleviates this, easily defined in package.json..

For your use case...

  • Expect an uploaded file (multipart): You would have to write an upload module that would expect a file upload and pipe the data to s3.. maybe you could make a micro-upload-to-s3 module ?
  • Expect posted binary data: then you would have to pipe the data yourself to s3. See also node IncomingMessage documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.