Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Upload local files nestjs

Copy and paste this decorator into the controller.

Check that the files directory has been created.


  @UseInterceptors(
    FileInterceptor('file', {
      storage: diskStorage({
        destination: './files',
        filename: (req, file, cb) => {
          const fileNameSplit = file.originalname.split('.');
          const fileExt = fileNameSplit[fileNameSplit.length - 1];
          cb(null, `${Date.now()}.${fileExt}`);
        },
      }),
    }),
  )
  @Post("/upload")
  create(
    @UploadedFile() file: Express.Multer.File,
  ) {
 	console.log(file)
  }
Source by www.instagram.com #
 
PREVIOUS NEXT
Tagged: #Upload #local #files #nestjs
ADD COMMENT
Topic
Name
2+2 =