我有一个 Amazon S3 的 postdata 预签名 URL。我想在空手道功能文件中使用它来上传文件(比如:pdf)
这是我需要使用空手道 POST 请求执行的示例 Curl 请求
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'
我从服务器收到响应(具有 preSignedUrl)并在功能文件中使用以下代码
"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>"
我试过了
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
我看到空手道日志的请求格式为:18:29:08.560 [ForkJoinPool-1-worker-3] DEBUG com.intuit.karate - request:
2 > POST https://s3.amazonaws.com/devtest
2 > Accept-Encoding: gzip,deflate
2 > Connection: Keep-Alive
2 > Content-Length: 10485
2 > Content-Type: multipart/form-data; boundary=xdW8JqUa4Z2DxRAQSN1i0LntgmN8ZII7VEBuJUs
2 > Host: s3.amazonaws.com
2 > User-Agent: Apache-HttpClient/4.5.11 (Java/13.0.1)
18:29:10.891 [ForkJoinPool-1-worker-3] DEBUG com.intuit.karate - response time in milliseconds: 2328.56
2 < 400
2 < Connection: close
2 < Content-Type: application/xml
2 < Date: Fri, 29 May 2020 12:59:09 GMT
2 < Server: AmazonS3
2 < Transfer-Encoding: chunked
2 < x-amz-id-2: IA9kNim1i7HTUx5RpMmyT34KrRdRj1UfbKGtiWQ7uoj4virV8Oq2UMU8vY/OBqn7T2SLk8VVgo4=
2 < x-amz-request-id: BF19F92FE6DB16E2
<?xml version="1.0" encoding="UTF-8"?>
我看到表单数据甚至没有在实际请求中传递但是我从 Amazon S3 收到验证 XML 错误,因为字段值的顺序不正确
<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>
我希望 204 No Content 和文件上传到 S3 存储桶