Tsed: [Decorator] MultipartFile

Created on 15 Jan 2017  路  11Comments  路  Source: tsedio/tsed

Improve doc enhancement

All 11 comments

@Controller('/')
class MyCtrl {
     @Post('/file')
     private uploadFile(@MultipartFile() file: Multer.File) {

     }

     @Post('/files')
     private uploadFile(@MultipartFile() files: Multer.File[]) {

     }
}

Hi @Romakita , how can Multer configuration be passed? I see that the only config available is the uploadDir through server settings.

Hi @m0uneer ,

Actually, global settings let you to customize the uploadDir. For more, options you need to give that to the MultipartFile decorators.

@MultipartFile(multerOptions)

See you

Hello! And where does the class Multer.File come from?

The https://romakita.github.io/ts-express-decorators/#/tutorials/upload-files-with-multer?id=example page does not describe where the Multer.File class comes from and the decorator @ MultipartFile.

Hi @khusamov ,

Multer come from the @types/multer and the decorator come from 'ts-express-decorators'.

Sorry, I'll fix the documentation soon :)

Thanks for the answer!

In the file @types/multer/index.d.ts I found only interface Express.Multer.File (line 99). But I can not understand how to connect it (with import).

I found how to connect the decorator MultipartFile with the help ofimport {MultipartFile} from 'ts-express-decorators / multipartfiles';. At you on a site in the documentation it is passed (

Hello @khusamov ,

Sorry for this mistake. I've just found the right example on my old project:

import {Controller, Post} from "ts-express-decorators";
import {Multer} from "@types/multer";

type MulterFile = Express.Multer.File;

@Controller('/')
class MyCtrl {

  @Post('/file')
  private uploadFile(@MultipartFile() file: MulterFile) {

  }

  @Post('/file')
  private uploadFile(@MultipartFile({dest: "/other-dir"}) file: MulterFile) {

  }
}

It works normally :)
See you !

Documentation will be updated soon ;)

@MultipartFile still not recognized, used the code from the documentation:

import { Controller, Get, Post } from '@tsed/common'
import Multer from 'multer'

type MulterFile = Express.Multer.File

export interface ViewerModel {
  name: string
  file: string
}

@Controller('/models')
export class ViewerModelCtrl {
  @Get('/')
  async renderModels() {
    return 'Hello World'
  }

  @Post('/')
  private uploadeModel(@MultiplartFile() file: MulterFile) {}
}

I get 'Cannot find name 'MultipartFile'

Solved by installing @tsed/multipartfiles and

import { MultipartFile } from '@tsed/multipartfiles'

In the documentation, @tsed/multipartfile is mentioned instead of @tsed/multipartfiles (plural)
And it looks like it should be used only for multiple files upload.

https://romakita.github.io/ts-express-decorators/#/tutorials/upload-files-with-multer?id=example

Hum ok. I'll fix this typo :) Thanks @naoric

Was this page helpful?
0 / 5 - 0 ratings