automation - 上传多部分纯文本时的空手道问题
问题描述
在空手道 0.9.6 中,我必须添加 * configure charset = null 才能使纯文本上传工作,当我升级到 1.0.1 时,我找不到任何适用于纯文本的方法。
我的pom:
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit5</artifactId>
<version>${karate.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.13.1</version>
</dependency>
我的场景:
Given path uuid, 'upload'
And multipart file file = ({read: filePath + fileName, filename: fileName, contentType: contentType})
And configure charset = null
When method POST
Then status 200
这适用于图像和 pdf 文件,但不适用于 contentType = "plain/text" 的 txt 文件
后端是一个 springboot 应用程序。该服务包含参数 @RequestPart(value = "file") MultipartFile content) ,并且像这样验证文件
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile
private boolean hasSupportedContentType(MultiPartFile multipartfile) {
String contentType = multipartFile.getContentType();
return contentType.equals(MediaType.TEXT_PLAIN_VALUE)
|| contentType.equals(MediaType.APPLICATION_PDF_VALUE);
}
由于 hasSupportedContentType 为 false,因此会引发以下错误。
有没有解决这个问题的方法?
解决方案
这可能是一个错误。您能否按照此处的说明进行一些研究:https ://github.com/intuit/karate/issues/1645#issuecomment-862502881
请注意,您也可以这样做(注意使用 ofvalue
代替read
:
* def value = karate.readAsString('my-file.txt')
* multipart file file = ({value: value, filename: 'test.txt' })
推荐阅读
- java - cpu使用率高和内存泄漏
- jscript - 有时不支持 Exists 属性
- c# - 选择对象集合的列/字段并导出为 List<>
- reactjs - 将全局变量与局部变量进行比较后如何重定向到另一条路由
- javascript - 从他们的 API 检索 Stripe 发票时,如何扩展对象以检索信用卡详细信息和其他信息?
- quill - How to get the last index of quill editor?
- java - 为什么 JTextfield 和 JButton 只在启动程序 3 次后才出现?
- c - 我怎样才能以这种方式拆分这个链表
- python - 与 Sqoop 不一致的结果
- java - 如何用随机整数填充矩阵而不重复它们?