Skip to content

Instantly share code, notes, and snippets.

@artworkad
Created November 23, 2017 16:13
Show Gist options
  • Save artworkad/dc7a4ab73eb4d45d6e1af3fb056e354c to your computer and use it in GitHub Desktop.
Save artworkad/dc7a4ab73eb4d45d6e1af3fb056e354c to your computer and use it in GitHub Desktop.
@Middleware()
export class MulterMiddleware implements NestMiddleware {
resolve(): (req, res, next) => void {
const upload = multer({ dest: "" });
return upload.any();
}
}
@Module({
modules: [DatabaseModule, HttpExceptionModule, LoggerModule, StorageModule],
controllers: [CatController],
components: [
CatService,
{ provide: CAT_REPOSITORY_TOKEN, useClass: CatMongodbRepository },
...catProviders
],
})
export class CatModule implements NestModule {
configure(consumer: MiddlewaresConsumer): void {
consumer.apply(MulterMiddleware).forRoutes(
{ path: '/cat/:id/cover', method: RequestMethod.POST }
);
}
}
@Controller('cat')
export class CatController {
@Post(':id/cover')
uploadCover(@Req() req, @Param('id') id){
console.log(id);
console.log(req.files);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment