Skip to content
New issue

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

Remove the deprecated addToBody option and return files as buffers when attachFieldsToBody is set to keyValues #481

Merged
merged 8 commits into from
Sep 28, 2023
Merged
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.
gurgunday marked this conversation as resolved.
Show resolved Hide resolved

```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.

Loading
Loading