How to call Amazon S3 bucket using postdata preSigned Url to upload a file using Karate

I have a postdata presigned URL of Amazon S3. I want to use it in a Karate feature file to upload a file (say: pdf)

Here is a sample Curl request that I need to perform Using Karate POST request

curl --location --request POST '<s3bucketURL>' \
--form 'key=some_key_fileName' \
--form 'x-amz-meta-payload={JsonObject}' \
--form 'Content-Type=application/pdf' \
--form 'bucket=<BucketName>' \
--form 'X-Amz-Algorithm=AWS4-HMAC-SHA256' \
--form 'X-Amz-Credential=<AWS_Credential>' \
--form 'X-Amz-Date=<Date>' \
--form 'Policy=<Policy_Hash>' \
--form 'X-Amz-Signature=<Signature_Hash>' \
--form 'file=@/Users/sahildua/validfile.pdf'  

I got a response (having the preSignedUrl) from a server and used using below code in a feature-file

  "url": "<s3bucketURL>",
  "fields": {
    "key": "some_key_fileName",
    "x-amz-meta-payload": "{JsonObject}",
    "Content-Type": "application/pdf",
    "bucket": "<BucketName>",
    "X-Amz-Algorithm": "AWS4-HMAC-SHA256",
    "X-Amz-Credential": "<AWS_Credential>",
    "X-Amz-Date": "<Date>",
    "Policy": "<Policy_Hash>",
    "X-Amz-Signature": "<Signature_Hash>"

I tried

Given url response.url
* def fieldData = response.fields
* print fieldData
* form fields fieldData
And multipart file file = { read: '../testData/validPdfFile.pdf'}
When method post
Then match responseStatus ==  204

But I get a validation XML error from Amazon S3 for incorrect field values

<Error> 
<Code>InvalidArgument</Code> 
<Message>Bucket POST must contain a field named 'key'. If it is specified, please check the order of the fields.</Message>
<ArgumentName>key</ArgumentName>
<ArgumentValue></ArgumentValue> 
<RequestId><id></RequestId> 
<HostId><someid></HostId> 
</Error>

I expect 204 No Content and the file to be uploaded the S3 bucket


Try this change:

And multipart file file = { read: '../testData/validPdfFile.pdf'}

Read this for a little more explanation: https://github.com/intuit/karate/tree/develop#multipart-file

Other than that you seem to be doing everything right. So it is up to your de-bugging skills now. Or give us a way to replicate: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue