【发布时间】:2021-07-08 10:31:00
【问题描述】:
在空手道 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,因此引发以下错误。
有没有办法解决这个问题?
【问题讨论】:
标签: automation karate