# nestjs-file-mimetype-filter

> A package where you can filter the filemimetype of the file you are going to upload.

Latest version **1.1.5** (published 2022-09-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install nestjs-file-mimetype-filter
pnpm add nestjs-file-mimetype-filter
yarn add nestjs-file-mimetype-filter
bun add nestjs-file-mimetype-filter
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2022-09-26 |
| First published | 2022-09-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 114.2 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Mustafa Kendigüzel |
| Maintainers | mustafakendiguzel |
| Keywords | file, file-upload, file-download, file-mimetype, file-mimetype-filter, nestjs, nestjs-file, nestjs-file-mimetype |

## Links

- npm: https://www.npmjs.com/package/nestjs-file-mimetype-filter
- Repository: https://github.com/mustafakendiguzel/nestjs-file-mimetype-filter
- Issues: https://github.com/mustafakendiguzel/nestjs-file-mimetype-filter/issues
- npm.io page: https://npm.io/package/nestjs-file-mimetype-filter

## Dependencies (6)

- [rxjs](https://npm.io/package/rxjs.md) ^7.2.0
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) ^9.0.0
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^9.0.0
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [@nestjs/platform-express](https://npm.io/package/@nestjs/platform-express.md) ^9.0.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.1.5 (latest) — 2022-09-26
- 1.1.4 — 2022-09-26
- 1.1.3 — 2022-09-26
- 1.1.2 — 2022-09-26
- 1.1.1 — 2022-09-26
- 1.1.0 — 2022-09-26
- 1.0.10 — 2022-09-26
- 1.0.9 — 2022-09-26
- 1.0.8 — 2022-09-26
- 1.0.6 — 2022-09-25
- 1.0.5 — 2022-09-25
- 1.0.4 — 2022-09-25
- 1.0.3 — 2022-09-24
- 1.0.2 — 2022-09-24
- 1.0.1 — 2022-09-24
- … 1 more at https://npm.io/package/nestjs-file-mimetype-filter/versions

## README

[![npm version](https://img.shields.io/npm/v/nestjs-file-mimetype-filter)](https://www.npmjs.com/package/nestjs-file-mimetype-filter)
[![npm download by month](https://img.shields.io/npm/dm/nestjs-file-mimetype-filter)](https://npmcharts.com/compare/nestjs-file-mimetype-filter?minimal=true)


## Description

[Nestjs file mimetype filter](https://github.com/mustafakendiguzel/nestjs-file-mimetype-filter) framework where you can filter the filemimetype of the file you are going to upload.

## Install

```bash
$ npm install nestjs-file-mimetype-filter
```

## Quick Start

```bash
# For import
$ import { ApiPdfFile,ApiImageFile,CustomFile } from 'nestjs-file-mimetype-filter';

```

## Example Usage
String of 'file' is the parameter name for uploadedFile from body
```bash
@ApiPdfFile({fileName:'file'})
  @Post()
  async create(@UploadedFile() file: Express.Multer.File, @Body() body: CreateConsentFormDto) {
    if (!file) {
      throw new UnprocessableEntityException('File is required!');
  }

```
## Access Multer Options 
You can access the multer options with localOptions parameter(Example)
[More about Multer Options](https://www.npmjs.com/package/multer)
```bash
@ApiPdfFile({fileName:'file', localOptions:{limits:{fileSize:1000}}})
  @Post()
  async create(@UploadedFile() file: Express.Multer.File, @Body() body: CreateConsentFormDto) {
    if (!file) {
      throw new UnprocessableEntityException('File is required!');
  }
```

You can combine with Swagger if you want 
```bash
@ApiPdfFile({fileName:'file', apiBodyType:ConsentFormBody })
@Post()
async create(@UploadedFile() file: Express.Multer.File, @Body() body:CreateConsentFormDto) {
  if (!file) {
    throw new UnprocessableEntityException('File is required!');
  }

```

## ConsentFormBody Example 
```bash
  export function ConsentFormBody() {
    return applyDecorators(
      ApiBody({
        schema: {
          type: 'object',
          properties: {
            name: { type: 'string' },
            file: {
              type: 'string',
              format: 'binary',
            },
            fileId: { type: 'string', nullable: true },
          },
        },
      })
    );
  }
```

## Other Usage

You can use for filtering images 
```bash
@ApiImageFile({fileName:'file'})
```
or Custom fileMimeType,You can select multiple types for you want
```bash
 @CustomFile(
    {
      fileName:'file',
      type:{allowedFiles:['image','pdf']},
    })
#or you can block files type you want
@CustomFile(
    {
      fileName:'file',
      type:{deniedFiles:['image','pdf']},
    })
#Don't use allowedFiles and deniedFiles together!
```

## Stay in touch

- Author - Mustafa Kendigüzel


## License

Nestjs-file-mimetype-filter [MIT licensed](LICENSE).

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