'Upload dynamic multiple files in Nest JS
I'm trying to upload files with dynamic keys, but nest.js needs to know key names.
I tried this one:
@UseInterceptors(FilesInterceptor('files'))
async uploadFile(@Query() minioDto: MinioDto, @UploadedFiles() files: Array<BufferedFile>) {
const {bucket} = minioDto;
return (await this.minioClientService.upload(files, bucket))?.name;
}
Here files are static, but I want dynamic like:
@UseInterceptors(FilesInterceptor())
async uploadFile(@Query() minioDto: MinioDto, @UploadedFiles() files: Array<BufferedFile>) {
const {bucket} = minioDto;
return (await this.minioClientService.upload(files, bucket))?.name;
}
I even tried to get files from the request but I couldn't
Solution 1:[1]
You can upload multiple files dynamically using AnyFilesInterceptor
provided by nest.js like below:
@Post('upload')
@UseInterceptors(AnyFilesInterceptor())
uploadFile(@UploadedFiles() files: Array<Express.Multer.File>) {
console.log(files);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hossein Mousavi |