【问题标题】:Karate problem when uploading multipart plain text [duplicate]上传多部分纯文本时的空手道问题[重复]
【发布时间】: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


    【解决方案1】:

    这可能是一个错误。您能否按照此处的说明进行一些研究:https://github.com/intuit/karate/issues/1645#issuecomment-862502881

    注意你也可以这样做(注意使用value而不是read

    * def value = karate.readAsString('my-file.txt')
    * multipart file file = ({value: value, filename: 'test.txt' })
    

    【讨论】:

    • 感谢您的快速回复!我的价值,它没有帮助。我尝试了链接,一切正常。我能发现的唯一区别是使用 postman 的 contet 类型有边界乞求 -----------------,而空手道则没有。我也尝试了最新版本 1.1.0.RC4 并且总是同样的问题。不知何故,spring框架无法正确识别MimeType
    • @mohallouli 很好-如果您提交一种复制方法会有所帮助,以便我们可以在需要时修复空手道:github.com/intuit/karate/wiki/How-to-Submit-an-Issue-但我真的认为 RC4 应该处理所有情况。您还可以编辑您的问题以包含一个有效的curl 请求
    • RC4 确实解决了我的其他问题。再次感谢您的支持。我可能会在下周创建一个问题
    • 嗨@Peter,我正在调查这个错误,真正的原因是“charset UTF-8”总是附加到 contentType,并且 * configure charset = null 不再删除它。
    • @mohallouli 所以请帮助我们修复它。你知道该怎么做
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多