dmitriy-nz / nestjs-form-data

NestJS middleware for handling multipart/form-data, which is primarily used for uploading files.
https://www.npmjs.com/package/nestjs-form-data
MIT License
117 stars 23 forks source link

add rename file #14

Open AmineHouari98 opened 2 years ago

AmineHouari98 commented 2 years ago

as the title said it would be nice to add a way to add a middleware to rename uploaded files before saving to local storage , i think this feature is a must when working with files !

dmitriy-nz commented 2 years ago

Hi, maybe add a callback function to the configuration of FormDataInterceptorConfig to get the filename before saving it to local storage?

chhonhourseng commented 2 years ago

Could you guide me with a callback function to the configuration of FormDataInterceptorConfig to get the filename?

tlikakur commented 1 year ago

Hi @AmineHouari98 @chhonhourseng

If you are using DTO, you can achieve this with @Transform decorator (class-transformer package):

@Transform(({ value }: { value: MemoryStoredFile }) => {
    value.originalName = 'new name';
    return value;
  })
file: MemoryStoredFile;
mamlzy commented 1 year ago

Hi, maybe add a callback function to the configuration of FormDataInterceptorConfig to get the filename before saving it to local storage?

can you give us the example? please.