Skip to content

Commit c195d5f

Browse files
gurgundayUzlopakFdawgs
authored
Remove the deprecated addToBody option and return files as buffers when attachFieldsToBody is set to keyValues (#481)
* Return buffers directly when `attachFieldsToBody` is set to `'keyValues'` (#468) * return buffer directly * add test * move tap path to taprc * update README.md * typo * refactor keyValues handler * use already set variable * use for...of * ditch for...of for Arrays * use keys rather than entries * Remove legacy addToBody and callback API (#465) * remove deprecated method * remove unused package * revert modification * remove addToBody documentation * remove request.multipart type * remove legacy comment * Use for loop for arrays and fix schema option for `keyValues` (#474) * only add schema when attachfieldstobody is true * fs/promises * use `for` for arrays * conditionally call Object.values * fix lint * Update test/multipart-attach-body.test.js Co-authored-by: Frazer Smith <[email protected]> * Update README.md Co-authored-by: Frazer Smith <[email protected]> --------- Co-authored-by: Uzlopak <[email protected]> Co-authored-by: Frazer Smith <[email protected]>
1 parent 1243b74 commit c195d5f

13 files changed

+95
-1970
lines changed

.taprc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
ts: false
2-
jsx: false
3-
flow: false
41
check-coverage: false
2+
files:
3+
- test/**/*.test.js

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ npm i @fastify/multipart
2222

2323
## Usage
2424

25-
If you are looking for the documentation for the legacy callback-api please see [here](./callback.md).
26-
2725
```js
2826
const fastify = require('fastify')()
2927
const fs = require('node:fs')
@@ -240,13 +238,13 @@ fastify.post('/upload/files', async function (req, reply) {
240238
})
241239
```
242240

243-
Request body key-value pairs can be assigned directly using `attachFieldsToBody: 'keyValues'`. Field values will be attached directly to the body object. By default, all files are converted to a string using `buffer.toString()` used as the value attached to the body.
241+
Request body key-value pairs can be assigned directly using `attachFieldsToBody: 'keyValues'`. Field values, including file buffers, will be attached to the body object.
244242

245243
```js
246244
fastify.register(require('@fastify/multipart'), { attachFieldsToBody: 'keyValues' })
247245

248246
fastify.post('/upload/files', async function (req, reply) {
249-
const uploadValue = req.body.upload // access file as string
247+
const uploadValue = req.body.upload // access file as buffer
250248
const fooValue = req.body.foo // other fields
251249
})
252250
```

callback.md

Lines changed: 0 additions & 194 deletions
This file was deleted.

examples/example-legacy-validation.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

examples/example-legacy.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)