Home > Back-end >  NestJS Multer set dest to an url
NestJS Multer set dest to an url

Time:12-27

Hello!

So, when i upload a file with nestjs and multer, i want to set the dest in the module to an url, but if i do that, then it gives me an error:

 EINVAL: invalid argument, mkdir 'C:\Users\almak\Desktop\Chatenium2\chatenium-server\http:\localhost'

Can you help me why? Thanks, and also is there any way to prevent nestjs from renaming and removing the file extension from the file (test.png => 03ebe1f47494378fee61196c0524afaf )

Heres the code:

Module:

    MulterModule.register({
      dest: process.env.CDN_URL,
    }),

Controller:


  @Post("uploadImg")
  @UseInterceptors(FileInterceptor("file"))
  async uploadedFile(@UploadedFile() file) {
    return file;
  }

CodePudding user response:

dest by default is a local directory for the server to access via the fs module. If you need to upload the file to another server from your server, you should use a different storage type.

As for the renaming of the file, that's also multer's default, you can pass options to the FileInterceptor according to multer's documentation to change how the file gets handled.

  • Related