# fastify-file-upload

> file upload plugin for Fastify

Latest version **4.0.0** (published 2022-04-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install fastify-file-upload
pnpm add fastify-file-upload
yarn add fastify-file-upload
bun add fastify-file-upload
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2022-04-20 |
| First published | 2018-03-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 76 |
| Author | huangang |
| Maintainers | huangang |
| Keywords | fastify, fileUpload, multipart, form |

## Links

- npm: https://www.npmjs.com/package/fastify-file-upload
- Repository: https://github.com/huangang/fastify-file-upload
- Homepage: https://github.com/huangang/fastify-file-upload#readme
- Issues: https://github.com/huangang/fastify-file-upload/issues
- npm.io page: https://npm.io/package/fastify-file-upload

## Dependencies (4)

- [middie](https://npm.io/package/middie.md) ^6.0.0
- [@types/node](https://npm.io/package/@types/node.md) ^16.11.0
- [fastify-plugin](https://npm.io/package/fastify-plugin.md) ^3.0.1
- [express-fileupload](https://npm.io/package/express-fileupload.md) ^1.3.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2022-04-20
- 3.0.1 — 2021-11-02
- 3.0.0 — 2020-07-10
- 2.1.0 — 2020-06-30
- 2.0.1 — 2019-08-07
- 2.0.0 — 2019-08-07
- 1.0.0 — 2018-11-26
- 0.1.1 — 2018-03-05
- 0.1.0 — 2018-03-05
- 0.0.1 — 2018-03-02

## README

# fastify-file-upload

Fastify plugin to upload file.

[![Build Status](https://travis-ci.org/huangang/fastify-file-upload.svg?branch=master)](https://travis-ci.org/huangang/fastify-file-upload)
[![NPM version](https://img.shields.io/npm/v/fastify-file-upload.svg?style=flat)](https://www.npmjs.com/package/fastify-file-upload)

__Note: the v3.x series of this module covers Fastify v3. For Fastify v2 support refert to the v2.x series.__

## Install
```
npm i fastify-file-upload --save
```
## Usage

```js
'use strict'

const fastify = require('fastify')()
const fileUpload = require('fastify-file-upload')

fastify.register(fileUpload)

fastify.post('/upload', function (req, reply) {
  // some code to handle file
  const files = req.raw.files
  console.log(files)
  let fileArr = []
  for(let key in files){
    fileArr.push({
      name: files[key].name,
      mimetype: files[key].mimetype
    })
  }
  reply.send(fileArr)
})

fastify.listen(3000, err => {
  if (err) throw err
  console.log(`server listening on ${fastify.server.address().port}`)
})
```
## Use Schema Demo (fastify version >= 2)
``` js
fastify.post('/uploadSchema', {
  schema: {
    summary: 'upload file',
    body: {
      type: 'object',
      properties: {
        file: { type: 'object' }
      },
      required: ['file']
    }
  },
  handler: (request, reply) => {
    const file = request.body.file
    console.log(file)
    reply.send({ file })
  }
})
```

## Using Busboy Options
```js
fastify.register(fileUpload, {
  limits: { fileSize: 50 * 1024 * 1024 },
});
```
### [Available Options](https://github.com/richardgirges/express-fileupload#available-options)

---
_Source: https://npm.io/package/fastify-file-upload · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
