NestJS
FileInterceptor
UseInterceptors(FileInterceptor('companyLogo', {
storage: diskStorage({
destination: (req, file, cb) => {
cb(null, './uploads/companies');
},
filename: (req, file, cb) => {
cb(null, `${file.originalname}`)
}
}),
fileFilter: (req, file, cb) => {
let ext = extname(file.originalname);
if(ext !== '.png' && ext !== '.jpg' && ext !== '.gif' && ext !== '.jpeg') {
return cb(new HttpException('Only images are allowed!',HttpStatus.BAD_REQUEST), null);
}
cb(null, true);
},
limits: {fileSize: 1024*1024}
}))
References