nestjs-file-mimetype-filter

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


Keywords
file, file-upload, file-download, file-mimetype, file-mimetype-filter, nestjs, nestjs-file, nestjs-file-mimetype
License
MIT
Install
npm install nestjs-file-mimetype-filter@1.1.5

Documentation

npm version npm download by month

Description

Nestjs file mimetype filter framework where you can filter the filemimetype of the file you are going to upload.

Install

$ npm install nestjs-file-mimetype-filter

Quick Start

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

Example Usage

String of 'file' is the parameter name for uploadedFile from body.(default:'file')

@ApiPdfFile('file')
  @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

@ApiPdfFile('file',ConsentFormBody)
  @Post()
  async create(@UploadedFile() file: Express.Multer.File, @Body() body: CreateConsentFormDto) {
    if (!file) {
      throw new UnprocessableEntityException('File is required!');
  }

ConsentFormBody Example

  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

@ApiImageFile('file',consentFormBody)

or Custom fileMimeType

@CustomFile('file','audio',consentFormBody)

Stay in touch

  • Author - Mustafa Kendigüzel

License

Nestjs-file-mimetype-filter MIT licensed.