1

In Karate 0.9.6, I had to add * configure charset = null for plain text upload to work, when I upgraded to 1.0.1, I can't find any way that works for plain text.

my 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>

my Scenario:

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

This works for images and pdf files but not with txt files with contentType = "plain/text"

The backend is a springboot app. The service contains the parameter @RequestPart(value = "file") MultipartFile content) , and the file is validated like this

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);

}

The following throws and excpetion because hasSupportedContentType is false.

Is there any workaround this problem?

mohallouli
  • 11
  • 1

1 Answers1

0

It can be a bug. Can you please do some research following the instructions here: https://github.com/intuit/karate/issues/1645#issuecomment-862502881

And note that you can also do this (note the use of value instead of read:

* def value = karate.readAsString('my-file.txt')
* multipart file file = ({value: value, filename: 'test.txt' })
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Thank you for the quick response! I with value and it did not help. I tried the link, everything works fine. The only difference I could spot is that the contet-type using postman has boundary begging with -----------------, while with karate it does not. I also tried the latest version 1.1.0.RC4 and always same problem. Somehow The spring framework does not recognize the MimeType correctly – mohallouli Jul 09 '21 at 09:57
  • @mohallouli well - it will help if you submit a way to replicate so we can fix karate if needed: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue - but I really think RC4 should handle all cases. you can also edit your question to include a working `curl` request – Peter Thomas Jul 09 '21 at 10:51
  • 1
    RC4 fixed my other problems indeed. Thank you again for your support. I will create an issue maybe next week – mohallouli Jul 09 '21 at 18:29
  • Hi @Peter, I was investigating into this bug, The real cause was that "charset UTF-8" was always appended to the contentType, and * configure charset = null does not remove it anymore. – mohallouli Nov 03 '21 at 10:42
  • @mohallouli so help us fix it please. you know what to do – Peter Thomas Nov 03 '21 at 11:06