Skip to content

Commit

Permalink
Remove the deprecated addToBody option and return files as buffers wh…
Browse files Browse the repository at this point in the history
…en 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 <frazer.dev@outlook.com>

* Update README.md

Co-authored-by: Frazer Smith <frazer.dev@outlook.com>

---------

Co-authored-by: Uzlopak <aras.abbasi@googlemail.com>
Co-authored-by: Frazer Smith <frazer.dev@outlook.com>
  • Loading branch information
3 people committed Sep 28, 2023
1 parent 1243b74 commit c195d5f
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 1,970 deletions.
5 changes: 2 additions & 3 deletions .taprc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ts: false
jsx: false
flow: false
check-coverage: false
files:
- test/**/*.test.js
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ npm i @fastify/multipart

## Usage

If you are looking for the documentation for the legacy callback-api please see [here](./callback.md).

```js
const fastify = require('fastify')()
const fs = require('node:fs')
Expand Down Expand Up @@ -240,13 +238,13 @@ fastify.post('/upload/files', async function (req, reply) {
})
```

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.
Request body key-value pairs can be assigned directly using `attachFieldsToBody: 'keyValues'`. Field values, including file buffers, will be attached to the body object.

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

fastify.post('/upload/files', async function (req, reply) {
const uploadValue = req.body.upload // access file as string
const uploadValue = req.body.upload // access file as buffer
const fooValue = req.body.foo // other fields
})
```
Expand Down
194 changes: 0 additions & 194 deletions callback.md

This file was deleted.

30 changes: 0 additions & 30 deletions examples/example-legacy-validation.js

This file was deleted.

37 changes: 0 additions & 37 deletions examples/example-legacy.js

This file was deleted.

0 comments on commit c195d5f

Please sign in to comment.