pranjal bhatia
pranjal bhatia

Reputation: 31

Multipart POST request not working in Karate 1.4.1 but works in Karate 1.2.0 and Postman

I’m facing an issue with a multipart POST request in Karate 1.4.1 that worked perfectly in Karate 1.2.0 and also works fine in Postman. The request is supposed to upload a file along with some metadata, but I keep getting a 400 Bad Request error.

Scenario:

I am trying to upload a file through a multipart POST request API in Karate. Here is the relevant part of my Karate script:

Feature: Upload Document

Scenario: Upload a document using multipart form-data

    Given path 'api/entity/entities'
    And request entyOrg
    When method post
    Then status 200
    And def entyresponse1 = response
    And def entityId1 = entyresponse1.id

    * def filePath1 = read('file:src/test/java/test_data/17.png')
    * def docPayload1 = [{ "entityId": '#(entityId1)', "ref": "ENTITY", "filename": "17.png", "contentType": "image/png" }]

    Given path 'api/document/documents/v2'
    * header Authorization = 'Bearer ' + accessToken
    And multipart file content = { value: '#(filePath1)', filename: "17.png", contentType: "image/png" }
    And multipart field meta = { value: '#(docPayload1)', contentType: "application/json" }
    When method post
    Then status 200

I receive the following error message:

status code was: 400, expected: 200, response time in milliseconds: 135, url: .., response: {"type":"about:blank","title":"Bad Request","status":400,"detail":"Failed to read request","instance":""}

What I’ve Tried:

  1. Checked for Breaking Changes: Reviewed the release notes for Karate 1.4.1 but couldn’t find anything specific to multipart requests.

  2. Updated Syntax: Ensured the syntax aligns with Karate 1.4.1 requirements.

  3. Debugging: Added print statements to log the payload and headers.

  4. Payload Structure: Verified that the payload structure matches what the server expects.

  5. Dependencies: Ensured all dependencies are compatible with Karate 1.4.1.

Additional Information:

Postman Curl Command:

curl --location 'https://gfciu-gateway-f.uki1f.paas.intranet.com/api/document/documents/v2' \\
    \--form 'content=@"postman-cloud:///1ef50dcd-32b1-4d20-9597-cc4a26da2a48"' \\
    \--form 'meta="\[{\\"entityId\\":24637,\\"entityRef\\":\\"PROJECT\\",\\"fileName\\":\\"17.png\\",\\"contentType\\":\\"image/png\\"}\]";type=application/json'
  1. Has anyone experienced a similar issue with multipart requests in Karate 1.4.1?

  2. Are there any known changes in how Karate 1.4.1 handles multipart requests that I might have missed?

  3. Any suggestions on how to resolve this issue?

Any help would be greatly appreciated!

Struggling for quite sometime on this issue.

Upvotes: 1

Views: 44

Answers (0)

Related Questions