Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type of object received during file upload using @UploadFile

In the REST API below, what is the type of file object that is received.

@Post('/:folderId/documents/:fileName')
@UseInterceptors(FileInterceptor('file'))
@ApiConsumes('multipart/form-data')
@ApiImplicitParam({ name: 'folderId', description: ' Folder Id' })
@ApiImplicitParam({ name: 'fileName', description: ' File Name' })
@ApiImplicitFile({ name: 'file', required: true, description: 'PDF File' })
async uploadFile(@UploadedFile() file, @Param() folderId, @Param() fileName) {
/**
 * I need to know the type of file object (first argument) of uploadFile
 */
    this.folderService.uploadFile(file, folderId, fileName);
}

I need to write a file received in the request to disk. How to do that?

like image 353
Amit Dube Avatar asked Dec 06 '18 10:12

Amit Dube


1 Answers

You can import the type from the package. '@types/multer' and then qualify the file as:

        @UploadedFile() file: Express.Multer.File,

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/multer/index.d.ts#L103

like image 163
christophercotton Avatar answered Oct 19 '22 13:10

christophercotton