@webundsoehne/nest-fastify-file-upload
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

Web und Söhne - Logo

Web & Söhne is Austria's leading expert in programming and implementing complex and large web projects.

Port of Nest's file upload and MulterModule for FastifyAdapter!

Compatibile with NestJS 7-10 and Fastify 3-4.

Steps:

Install to your project:

npm i @webundsoehne/nest-fastify-file-upload

IMPORTANT: Register contentParser in your root application after creation:

import { NestFactory } from '@nestjs/core'
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify'
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'
import { contentParser } from 'fastify-multer'

import { AppModule } from './app.module'

async function bootstrap (): Promise<void> {
  const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter())

  await app.register(contentParser)

  await app.listen(3000)
}

bootstrap()

Use it like the official NestJS package for Express in your controllers:

@Post('upload')
@UseInterceptors(FileInterceptor('file'))
@ApiFileBody('file')
@ApiConsumes('multipart/form-data')
uploadFile (@UploadedFile('file') file: MulterFile): void {
    console.log(file)
}

...

The package will export the missing Express.Multer.* types as Multer*.

more information: https://docs.nestjs.com/techniques/file-upload

@ApiFileBody Decorator

Useful controller decorator that adds file upload functionality in Swagger.

You can specify the file key as parameter, default key is file.

MulterModule

Register the MulterModule e.g. to directly upload to a specified directory.

import { Module } from '@nestjs/common'

import { AppController } from './app.controller'
import {MulterModule} from "../multer.module";

@Module({
  controllers: [AppController],
  imports: [
      MulterModule.register({dest: './uploads'})
  ]
})
export class AppModule { }

more information and options: https://docs.nestjs.com/techniques/file-upload#default-options

Stay in touch

Package Sidebar

Install

npm i @webundsoehne/nest-fastify-file-upload

Weekly Downloads

782

Version

2.2.0

License

ISC

Unpacked Size

151 kB

Total Files

54

Last publish

Collaborators

  • ws-admin
  • dabls