Skip to content

Commit

Permalink
docs: update for attachFieldsToBody: keyValues (#492)
Browse files Browse the repository at this point in the history
* docs: update for attachFieldsToBody: keyValues

* fix docs to match fastify style guide
  • Loading branch information
dancastillo authored Oct 23, 2023
1 parent e497c21 commit 9ff3c28
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ If you try to read from a stream and pipe to a new file, you will obtain an empt

## JSON Schema body validation

If you enable `attachFieldsToBody: 'keyValues'` then the response body and JSON Schema validation will behave similarly to `application/json` and [`application/x-www-form-urlencoded`](https://github.com/fastify/fastify-formbody) content types. Files will be decoded using `Buffer.toString()` and attached as a body value.
When the `attachFieldsToBody` parameter is set to `'keyValues'`, JSON Schema validation on the body will behave similarly to `application/json` and [`application/x-www-form-urlencoded`](https://github.com/fastify/fastify-formbody) content types. Additionally, uploaded files will be attached to the body as `Buffer` objects.

```js
fastify.register(require('@fastify/multipart'), { attachFieldsToBody: 'keyValues' })
Expand All @@ -302,9 +302,7 @@ fastify.post('/upload/files', {
properties: {
// file that gets decoded to string
myFile: {
type: 'string',
// validate that file contents match a UUID
pattern: '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
type: 'object',
},
hello: {
type: 'string',
Expand Down

0 comments on commit 9ff3c28

Please sign in to comment.