繁体   English   中英

如何使用 typescript 在 node.js 中获取具有其他参数的图像文件?

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

我以单一形式获取图像文件和其他参数。 我正在使用路由控制器(npm 库)装饰器来获取文件@UploadedFile("image") file?: any并在正文中获取其他参数@Body({ required: true }) review: ReviewInput 有什么好方法可以获取这些参数吗? ReviewInput是我定义的类型,其中包含字符串参数以下是我获取参数的代码:

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

return AddReviewsUsecase.execute(review, file);

}

如果正文中的参数很少,则可以使用@BodyParam() 例子:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM