Reputation: 31
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.
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":""}
Checked for Breaking Changes: Reviewed the release notes for Karate 1.4.1 but couldn’t find anything specific to multipart requests.
Updated Syntax: Ensured the syntax aligns with Karate 1.4.1 requirements.
Debugging: Added print
statements to log the payload and headers.
Payload Structure: Verified that the payload structure matches what the server expects.
Dependencies: Ensured all dependencies are compatible with Karate 1.4.1.
The same API call works fine in Postman.
Reverting back to Karate 1.2.0 resolves the issue, but I need to use Karate 1.4.1 for other features.
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'
Has anyone experienced a similar issue with multipart requests in Karate 1.4.1?
Are there any known changes in how Karate 1.4.1 handles multipart requests that I might have missed?
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