Search code examples
javascriptnode.jsrestnestjs

How to accept .psd, .avi, .mov files in nestjs file interceptor?


I am trying to accept multiple images in my request body, The files I am having problems are .mov, .psd, .avi.

This is my current code snippet

@UseInterceptors(FilesInterceptor('upload_image', 10))
  async uploadImage(
    @UploadedFiles(
      new ParseFilePipe({
        validators: [
          new FileTypeValidator({
            fileType: '.(png|jpeg|jpg|pdf|gif|svg|mp4|psd|bmp|mov|avi)',
          }),
          new MaxFileSizeValidator({ maxSize: 1024 * 1024 * 4 }),
        ],
      }),
    )
    files,
    @Body() body: UploadFileDto,
    @Req() req,
    @Res() res,
  ) {
// Some service logic
}

Iam getting the below response after selecting .avi , .mov, .psd files

{
    "statusCode": 400,
    "message": "Validation failed (expected type is .(png|jpeg|jpg|pdf|gif|svg|mp4|psd|bmp|mov|avi))",
    "error": "Bad Request"
}

It accepts file for evry other format other than the formats mentioned above.


Solution

  • Try adding mimeType as well. May be its throwing as mimeType is not mentioned. Refer this piece of code fileType: '^.*.(mov|quicktime|photoshop)$',