Socket
Book a DemoInstallSign in
Socket

@webundsoehne/nest-fastify-file-upload

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webundsoehne/nest-fastify-file-upload

Port of NestJS FileInterceptor & MulterModule for FastifyAdapter

2.3.1
latest
npmnpm
Version published
Weekly downloads
2.4K
9.46%
Maintainers
2
Weekly downloads
 
Created
Source

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-11 and Fastify 3-5.

Steps:

Application Setup

Install to your project:

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

Configure your NestApplication to use the correct body parser.

Nest 11+ / Fastify 5

Install npm i @fastify/multipart as multipart body parser.

Register fastifyMultipart in your root application after creation:

import { NestFactory } from '@nestjs/core'
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify'
import { fastifyMultipart } from '@fastify/multipart'

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

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

  await app.register(fastifyMultipart)

  await app.listen(3000)
}

Nest <= 10 / Fastify 3-4

Register contentParser in your root application after creation:

import { NestFactory } from '@nestjs/core'
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify'
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()

File Controller Setup

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

  • Do you have any additional questions?
  • Author: Backend Team
  • Website: Web & Söhne

Keywords

nestjs

FAQs

Package last updated on 28 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.