Karate Lab - How to send binary file instead of multipart form?

41 Views Asked by At
  • I follow the example upload.feature but Karate seems only allow multipart form request.
Scenario: Successul
        * karate.log(token, auth, common_headers)
        Given url 'https://webhook.site/e026040f-68ac-45e9-8add-c839fd46f0ba'
        And multipart field image = read('images/img1.png')
        And header Content-Type = 'image/png'
        When method PUT
        Then status 200
  • This would probably translate to the follow curl command (from Postman)
curl --location --request PUT 'https://staging-ah.naluri.net/food-journal/upload?x-pri-id=qedSdhZU7UmXXztqFJyJw&x-verify-id=P2KUBtR07Qqk3j6U7tGrG' \
--header 'Content-Type: image/png' \
--form 'file=@"/Users/dennis.dao/workspace/repo/sample/karate-ui-sample/images/img1.png"'
  • This is what I would like to achieve the following
curl --location --request PUT 'https://staging-ah.naluri.net/food-journal/upload?x-pri-id=qedSdhZU7UmXXztqFJyJw&x-verify-id=P2KUBtR07Qqk3j6U7tGrG' \
--header 'Content-Type: image/png' \
--data '@images/img1.png'
1

There are 1 best solutions below

1
simbataisa On

I found the solution:

Scenario: Successul
    Given url 'https://webhook.site/e026040f-68ac-45e9-8add-c839fd46f0ba'
    And header Content-Type = 'image/png'
    * def image = read('images/img1.png')
    And request image
    When method PUT
    Then status 200
    When method PUT
    Then status 200