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

Question: How to upload a file? #35

Closed
cemremengu opened this issue Feb 19, 2019 · 2 comments
Closed

Question: How to upload a file? #35

cemremengu opened this issue Feb 19, 2019 · 2 comments

Comments

@cemremengu
Copy link
Contributor

I would like to upload multipart/form-data using inject. Currently, using this plugin to get the files but I am unable to do so.

Is this possible?

@mcollina
Copy link
Member

mcollina commented Feb 19, 2019 via email

@cemremengu
Copy link
Contributor Author

cemremengu commented Feb 19, 2019

Thank you! Ended up with:

  const FormData = require('form-data')
  const form = new FormData()
  form.append('myfile', fs.createReadStream(`./path/to/file`))

  const res = await app.inject({
    url: '/api/upload'
    method: 'POST',
    payload: form,
    headers: form.getHeaders()
  })

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

2 participants