File Uploads

Nova supports multipart file uploads out of the box using the @File decorator. Files are handled via @fastify/multipart.

Basic Usage

upload.controller.ts TypeScript
import { Controller, Post, File, MultipartFile } from '@abrahambass/nova';

@Controller('/uploads')
class UploadController {

  @Post('/avatar')
  async uploadAvatar(
    @File('avatar') file: MultipartFile,
  ) {
    return {
      filename: file.filename,
      mimetype: file.mimetype,
      encoding: file.encoding,
    };
  }
}

Optional Files

Example TypeScript
@Post('/profile')
async updateProfile(
  @File('avatar') avatar: MultipartFile,
  @File('cover', { optional: true }) cover?: MultipartFile,
) {
  // `avatar` is required, `cover` is optional
}
💡 Note

The request must have Content-Type: multipart/form-data. If not, a validation error is returned with message: "Content-Type must be multipart/form-data".

MultipartFile Properties

PropertyTypeDescription
filenamestringOriginal filename
mimetypestringMIME type (e.g. image/png)
encodingstringEncoding (e.g. 7bit)
fieldnamestringName of the form field
fileReadableStream to read file contents
toBuffer()Promise<Buffer>Read the entire file as a buffer