How to get image file with other parameters in node.js using typescript?

Viewed 331

I am getting an image file and other parameters in a single form. I am using routing-controller (npm library) decorator to get the file @UploadedFile("image") file?: any and getting other params in body @Body({ required: true }) review: ReviewInput. Is there any good way to get these params? ReviewInput is my defined type which contains the string params following is the code where I am getting params:

@Post("/review")
async addReview(
@Body({ required: true }) review: ReviewInput,
@UploadedFile("image") file?: any,) {

return AddReviewsUsecase.execute(review, file);

}
1 Answers

You can use @BodyParam() if you have few parameters in body. Example:

@Post("/review")
async addReview(
    @BodyParam() review: string,
    @BodyParam() rating: number,
    @UploadedFile("image") file?: any,
) {
    return AddReviewsUsecase.execute(review, file);
}
Related