Closed
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.1.0
Plugin version
7.1.0
Node.js version
v16.14.2
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
12.3
Description
In my case, when I apply { attachFieldsToBody: 'keyValues' }
, the uploaded image was been stringified from buffer with buffer.toString()
which is default to uft-8 encoding. And it might not able to be converted correctly back to the buffer.
Line 157 in 80d9509
Maybe buffer.toString('binary')
or buffer.toString('base64')
is more general and acceptable encoding.
If there is no other concern I could make a PR for it.
Steps to Reproduce
import fastifyMultipart from '@fastify/multipart'
import { writeFile} from 'fs/promises'
app.register(fastifyMultipart, { attachFieldsToBody: 'keyValues' })
app.post('upload', async (req, reply) => {
const buffer = Buffer.from(req.image)
await writeFile('path', buffer) // which is not a valid image
reply.send()
})
Expected Behavior
The written image should be read correctly.
Metadata
Metadata
Assignees
Labels
No labels