We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
We're sending data as in example bellow, due to this line:
if (request.raw.files) { for (const key in request.raw.files) { request.body[key] = request.raw.files[key] } }
They got ignored and therefore not added into body, so I hope this helps somebody, @huangang maybe consider adding following 🙂
import fp from 'fastify-plugin' import fileUpload from 'express-fileupload' const setMultipart = (request, done): void => { request[Symbol('multipart')] = true done() } const fastifyUpload = (fastify, options, done) => { fastify.addContentTypeParser('multipart', setMultipart) options = options || {} fastify.use(fileUpload(options)) fastify.addHook('preValidation', (request, reply, done) => { if (request.raw) { !request.body && (request.body = request.raw.body || {}) if (request.raw.files) { request.body = { ...request.raw.body, ...request.raw.files } } } done() }) done() } export default fp(fastifyUpload, { fastify: '>= 2.0.0', name: 'fastify-file-upload' })
Example request
PUT http://localhost:3000/registration/938cecf7-fa10-4580-a4bd-978ca34f3b67 Content-Type: multipart/form-data; boundary=WebAppBoundary x-token: vDkhBTJCwsdov0t55bzu4UHIN9AXZgYJGz3Fq326Rske8ZCm --WebAppBoundary Content-Disposition: form-data; name="files"; filename="logo.png" Content-Type: image/png < ./input.pdf --WebAppBoundary Content-Disposition: form-data; name="files"; filename="logo.png" Content-Type: image/png < ./input.png --WebAppBoundary Content-Disposition: form-data; name="data" {} --WebAppBoundary--
The text was updated successfully, but these errors were encountered:
Can you provide an example repositories? I want to try
Sorry, something went wrong.
Suppose the backend needs to receive the imageKey field, array type, and the frontend uses formdata to pass it.
imageKey has strings and streams of files,
Now that raw.files overwrites the body, the string part of imageKey is missing.
4.0.0 also has bugs, waiting to be updated by the author
No branches or pull requests
We're sending data as in example bellow, due to this line:
They got ignored and therefore not added into body, so I hope this helps somebody, @huangang maybe consider adding following 🙂
Example request
The text was updated successfully, but these errors were encountered: