From a3fe8364ec1bcefb6e65be8be0651fccd65fb23a Mon Sep 17 00:00:00 2001 From: "dan.castillo" Date: Sat, 21 Oct 2023 21:06:10 -0400 Subject: [PATCH 1/2] docs: update for attachFieldsToBody: keyValues --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6a1b2e13..9da09047 100644 --- a/README.md +++ b/README.md @@ -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. +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` and attached as a body value. ```js fastify.register(require('@fastify/multipart'), { attachFieldsToBody: 'keyValues' }) @@ -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', From 429b1fd549b92039ebadfedf5a7442227640427e Mon Sep 17 00:00:00 2001 From: "dan.castillo" Date: Sun, 22 Oct 2023 15:22:28 -0400 Subject: [PATCH 2/2] fix docs to match fastify style guide --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9da09047..e0369919 100644 --- a/README.md +++ b/README.md @@ -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` 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' })