Untitled
unknown
typescript
a year ago
960 B
2
Indexable
Never
@Post('file') @UseInterceptors( FileInterceptor('file', { storage: diskStorage({ destination: 'res/img', filename: (req, file, cb) => { const randomName = Array(32) .fill(null) .map(() => Math.round(Math.random() * 16).toString(16)) .join(''); cb(null, `${randomName}${extname(file.originalname)}`); }, }), //todo file image filter bisa di bikin di utils sementara disini. fileFilter: (req, file, cb) => { if (file.mimetype.match(/\/(jpg|jpeg|png)$/)) { cb(null, true); //* pake regex } else { cb( new HttpException( `Unsupported file type ${extname(file.originalname)}`, HttpStatus.BAD_REQUEST, ), false, ); } }, }), ) async uploadHandler(@UploadedFile() file) { return file; } }