fastify-multipart v 3.0 not able to access key/value pairs with upload binary file
See original GitHub issue🐛 Bug Report
Thanks for improving this plugin to make it easier for files upload. I’ve switched over to v3.0 and tried out the new API but it’s not letting me access the fields data like the legacy version
To Reproduce
Steps to reproduce the behavior:
Client form
const formData = new FormData();
formData.append("avatar", file, file.name); // <input type="file" />
formData.append("testData", JSON.stringify({ name: "Foo" }));
fetch("/", {
method: "POST",
body: formData
})
Server
fastify.post('/', async function (req, reply) {
const data = await req.file()
data.file // stream
data.fields // other parsed parts
data.fieldname
data.filename
data.encoding
data.mimetype
console.log(JSON.parse(data.fields))
await pump(data.file, fs.createWriteStream(data.filename))
reply.send()
})
Expected behavior
print out { name: ‘Foo’ }
in the legacy version, i could access it under this:
mp.on('field', function (key, value) {
console.log(JSON.parse(value))
})
Your Environment
- node version: 12
- fastify version: >=3.0.0
- os: Mac
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Fastify Multipart File Upload - Backend Cafe
Fastify manages multipart form data to save uploaded files. Upload your files using axios or fetch.
Read more >How to handle Node.js file uploads with Fastify - Snyk
To do this, you need to import multipart from '@fastify/multipart' and then register it. Here you registered multipart on the Fastify app you ......
Read more >formzilla - npm
Fastify plugin for parsing multipart/form data. Latest version: 3.0.0, last published: 12 hours ago. Start using formzilla in your project ...
Read more >Nestjs - file upload with fastify multipart - Stack Overflow
2 Answers 2 · i need to use fastify with nestjs to post fields(not files) multipart data. In both my application and your...
Read more >Uploading a File to a Server from Flutter Using a Multi-Part ...
Usually, the body of a POST request is made of textual key-value pairs. With a multipart POST request, you can also include files...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We can’t parse out of sync because files must be handled first. In order to achieve your result, you have to reorder your form
or you use
multipartIterator()
to iterate over field and files.