diff --git a/README.md b/README.md index 26467930..d7979e1f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# fastify-multipart +# @fastify/multipart ![CI](https://github.com/fastify/fastify-multipart/workflows/CI/badge.svg) -[![NPM version](https://img.shields.io/npm/v/fastify-multipart.svg?style=flat)](https://www.npmjs.com/package/fastify-multipart) +[![NPM version](https://img.shields.io/npm/v/@fastify/multipart.svg?style=flat)](https://www.npmjs.com/package/@fastify/multipart) [![Known Vulnerabilities](https://snyk.io/test/github/fastify/fastify-multipart/badge.svg)](https://snyk.io/test/github/fastify/fastify-multipart) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) @@ -18,7 +18,7 @@ Under the hood it uses [`@fastify/busboy`](https://github.com/fastify/busboy). ## Install ```sh -npm i --save fastify-multipart +npm i --save @fastify/multipart ``` ## Usage @@ -33,7 +33,7 @@ const path = require('path') const { pipeline } = require('stream') const pump = util.promisify(pipeline) -fastify.register(require('fastify-multipart')) +fastify.register(require('@fastify/multipart')) fastify.post('/', async function (req, reply) { // process a single file @@ -70,7 +70,7 @@ fastify.listen(3000, err => { }) ``` -**Note** about `data.fields`: `busboy` consumes the multipart in serial order (stream). Therefore, the order of form fields is *VERY IMPORTANT* to how `fastify-multipart` can display the fields to you. +**Note** about `data.fields`: `busboy` consumes the multipart in serial order (stream). Therefore, the order of form fields is *VERY IMPORTANT* to how `@fastify/multipart` can display the fields to you. We would recommend you place the value fields first before any of the file fields. It will ensure your fields are accessible before it starts consuming any files. If you cannot control the order of the placed fields, be sure to read `data.fields` *AFTER* consuming the stream, or it will only contain the fields parsed at that moment. @@ -78,7 +78,7 @@ If you cannot control the order of the placed fields, be sure to read `data.fiel You can also pass optional arguments to `@fastify/busboy` when registering with Fastify. This is useful for setting limits on the content that can be uploaded. A full list of available options can be found in the [`@fastify/busboy` documentation](https://github.com/fastify/busboy#busboy-methods). ```js -fastify.register(require('fastify-multipart'), { +fastify.register(require('@fastify/multipart'), { limits: { fieldNameSize: 100, // Max field name size in bytes fieldSize: 100, // Max field value size in bytes @@ -226,7 +226,7 @@ fastify.post('/upload/file', async function (req, reply) { This allows you to parse all fields automatically and assign them to the `request.body`. By default files are accumulated in memory (Be careful!) to buffer objects. Uncaught errors are [handled](https://github.com/fastify/fastify/blob/master/docs/Hooks.md#manage-errors-from-a-hook) by Fastify. ```js -fastify.register(require('fastify-multipart'), { attachFieldsToBody: true }) +fastify.register(require('@fastify/multipart'), { attachFieldsToBody: true }) fastify.post('/upload/files', async function (req, reply) { const uploadValue = await req.body.upload.toBuffer() // access files @@ -244,7 +244,7 @@ async function onFile(part) { await pump(part.file, fs.createWriteStream(part.filename)) } -fastify.register(require('fastify-multipart'), { attachFieldsToBody: true, onFile }) +fastify.register(require('@fastify/multipart'), { attachFieldsToBody: true, onFile }) fastify.post('/upload/files', async function (req, reply) { const fooValue = req.body.foo.value // other fields @@ -264,7 +264,7 @@ const opts = { attachFieldsToBody: true, sharedSchemaId: '#mySharedSchema' } -fastify.register(require('fastify-multipart'), opts) +fastify.register(require('@fastify/multipart'), opts) fastify.post('/upload/files', { schema: { @@ -366,7 +366,7 @@ const opts = { attachFieldsToBody: true, sharedSchemaId: '#mySharedSchema' } -fastify.register(require('fastify-multipart'), opts) +fastify.register(require('@fastify/multipart'), opts) fastify.post('/upload/files', { schema: { @@ -402,7 +402,7 @@ fastify.post('/upload/files', { ## Access all errors -We export all custom errors via a server decorator `fastify.multipartErrors`. This is useful if you want to react to specific errors. They are derived from [fastify-error](https://github.com/fastify/fastify-error) and include the correct `statusCode` property. +We export all custom errors via a server decorator `fastify.multipartErrors`. This is useful if you want to react to specific errors. They are derived from [@fastify/error](https://github.com/fastify/fastify-error) and include the correct `statusCode` property. ```js fastify.post('/upload/files', async function (req, reply) { diff --git a/callback.md b/callback.md index 64ca97d8..17f9052a 100644 --- a/callback.md +++ b/callback.md @@ -14,7 +14,7 @@ const concat = require('concat-stream') const fs = require('fs') const pump = require('pump') -fastify.register(require('fastify-multipart')) +fastify.register(require('@fastify/multipart')) fastify.post('/', function (req, reply) { // you can use this request's decorator to check if the request is multipart @@ -68,7 +68,7 @@ You can also pass optional arguments to busboy when registering with fastify. Th This behavior is inherited from [busboy](https://github.com/mscdex/busboy). ```js -fastify.register(require('fastify-multipart'), { +fastify.register(require('@fastify/multipart'), { limits: { fieldNameSize: 100, // Max field name size in bytes fieldSize: 1000000, // Max field value size in bytes @@ -132,7 +132,7 @@ const options = { limit: { /*...*/ } // You can the limit options in any case } -fastify.register(require('fastify-multipart'), options) +fastify.register(require('@fastify/multipart'), options) fastify.post('/', function (req, reply) { console.log(req.body)