Skip to content

Commit 2f7deef

Browse files
authored
docs: update references to old fastify-* modules (#342)
1 parent d0aa9cb commit 2f7deef

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# fastify-multipart
1+
# @fastify/multipart
22

33
![CI](https://github.com/fastify/fastify-multipart/workflows/CI/badge.svg)
4-
[![NPM version](https://img.shields.io/npm/v/fastify-multipart.svg?style=flat)](https://www.npmjs.com/package/fastify-multipart)
4+
[![NPM version](https://img.shields.io/npm/v/@fastify/multipart.svg?style=flat)](https://www.npmjs.com/package/@fastify/multipart)
55
[![Known Vulnerabilities](https://snyk.io/test/github/fastify/fastify-multipart/badge.svg)](https://snyk.io/test/github/fastify/fastify-multipart)
66
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
77

@@ -18,7 +18,7 @@ Under the hood it uses [`@fastify/busboy`](https://github.com/fastify/busboy).
1818

1919
## Install
2020
```sh
21-
npm i --save fastify-multipart
21+
npm i --save @fastify/multipart
2222
```
2323

2424
## Usage
@@ -33,7 +33,7 @@ const path = require('path')
3333
const { pipeline } = require('stream')
3434
const pump = util.promisify(pipeline)
3535

36-
fastify.register(require('fastify-multipart'))
36+
fastify.register(require('@fastify/multipart'))
3737

3838
fastify.post('/', async function (req, reply) {
3939
// process a single file
@@ -70,15 +70,15 @@ fastify.listen(3000, err => {
7070
})
7171
```
7272

73-
**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.
73+
**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.
7474
We would recommend you place the value fields first before any of the file fields.
7575
It will ensure your fields are accessible before it starts consuming any files.
7676
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.
7777

7878
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).
7979

8080
```js
81-
fastify.register(require('fastify-multipart'), {
81+
fastify.register(require('@fastify/multipart'), {
8282
limits: {
8383
fieldNameSize: 100, // Max field name size in bytes
8484
fieldSize: 100, // Max field value size in bytes
@@ -226,7 +226,7 @@ fastify.post('/upload/file', async function (req, reply) {
226226
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.
227227

228228
```js
229-
fastify.register(require('fastify-multipart'), { attachFieldsToBody: true })
229+
fastify.register(require('@fastify/multipart'), { attachFieldsToBody: true })
230230

231231
fastify.post('/upload/files', async function (req, reply) {
232232
const uploadValue = await req.body.upload.toBuffer() // access files
@@ -244,7 +244,7 @@ async function onFile(part) {
244244
await pump(part.file, fs.createWriteStream(part.filename))
245245
}
246246

247-
fastify.register(require('fastify-multipart'), { attachFieldsToBody: true, onFile })
247+
fastify.register(require('@fastify/multipart'), { attachFieldsToBody: true, onFile })
248248

249249
fastify.post('/upload/files', async function (req, reply) {
250250
const fooValue = req.body.foo.value // other fields
@@ -264,7 +264,7 @@ const opts = {
264264
attachFieldsToBody: true,
265265
sharedSchemaId: '#mySharedSchema'
266266
}
267-
fastify.register(require('fastify-multipart'), opts)
267+
fastify.register(require('@fastify/multipart'), opts)
268268

269269
fastify.post('/upload/files', {
270270
schema: {
@@ -366,7 +366,7 @@ const opts = {
366366
attachFieldsToBody: true,
367367
sharedSchemaId: '#mySharedSchema'
368368
}
369-
fastify.register(require('fastify-multipart'), opts)
369+
fastify.register(require('@fastify/multipart'), opts)
370370

371371
fastify.post('/upload/files', {
372372
schema: {
@@ -402,7 +402,7 @@ fastify.post('/upload/files', {
402402

403403
## Access all errors
404404

405-
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.
405+
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.
406406

407407
```js
408408
fastify.post('/upload/files', async function (req, reply) {

callback.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const concat = require('concat-stream')
1414
const fs = require('fs')
1515
const pump = require('pump')
1616

17-
fastify.register(require('fastify-multipart'))
17+
fastify.register(require('@fastify/multipart'))
1818

1919
fastify.post('/', function (req, reply) {
2020
// 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
6868
This behavior is inherited from [busboy](https://github.com/mscdex/busboy).
6969

7070
```js
71-
fastify.register(require('fastify-multipart'), {
71+
fastify.register(require('@fastify/multipart'), {
7272
limits: {
7373
fieldNameSize: 100, // Max field name size in bytes
7474
fieldSize: 1000000, // Max field value size in bytes
@@ -132,7 +132,7 @@ const options = {
132132
limit: { /*...*/ } // You can the limit options in any case
133133
}
134134

135-
fastify.register(require('fastify-multipart'), options)
135+
fastify.register(require('@fastify/multipart'), options)
136136

137137
fastify.post('/', function (req, reply) {
138138
console.log(req.body)

0 commit comments

Comments
 (0)