javascript - 您可以将 FileInterceptor 与 TransformPipe 一起使用吗
问题描述
我遇到了一个问题TransformPipe
- 只要我不使用FileInterceptor
. 由于我需要这两种功能,这让我很困惑。我在 Github 上创建了一个问题,但卡米尔在上面写道,这是一种正常的框架行为。我和我的朋友也没有在官方文档中找到任何对这种“正常”行为的引用。你有什么想法?
代码在这里:
控制器
@UsePipes(SamplePipe)
@UseInterceptors(FileInterceptor('file'))
@Post()
samplePost(@UploadedFile() file) {
return file
}
管道
@Injectable()
export class SamplePipe implements PipeTransform {
transform(value: any, metadata: ArgumentMetadata) {
console.log("I'm working")
return value;
}
}
解决方案
Pipes
仅适用于以下类型:'body' | 'query' | 'param' | 'custom'
对应于@Body()
、或自定义装饰器@Query()
,如. 在您的示例中,您没有任何这些,这就是不应用管道的原因。@Param()
@User()
因此,如果您将其中之一添加到您的示例中,则将应用管道(在本例中为@Body()
)。
@UsePipes(SamplePipe)
@UseInterceptors(FileInterceptor('file'))
@Post()
samplePost(@UploadedFile() file, @Body() body) {
^^^^^^^^^^^^^
return file
}
如果您使用@UsePipes()
管道,将适用于任何适用的地方。您也可以使用@Body(SimplePipe) body
仅将管道应用于主体。
推荐阅读
- leaflet - 有人知道更多关于传单的 ALK Maps 插件吗?我想使用他们的地图,但我似乎找不到 api 密钥
- puppet - Puppet Open Source 连接到 PuppetDB 还是 DB?
- android - 调用第二个回收器视图单击第一个回收器视图项单击时的数据
- python - 无法使用 PyCharm 和 venv 导入 TF
- android - 为什么 DependencyResolveDetails 以红色突出显示
- python - 如何将 spark 数据框列名和行数据转换为 json 数据
- sql-server - 为什么无法重命名数据库
- ios - UITableView滚动时如何退出textview
- php - symfony4.2 中的 Swiftmailer 单元/功能测试
- python-3.x - shell和systemd之间的stderr输出不一致