Created
November 23, 2017 16:13
-
-
Save artworkad/dc7a4ab73eb4d45d6e1af3fb056e354c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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