问题描述
我有一个Amazon S3的后数据预签名URL.我想在空手道特征文件中使用它来上传文件(例如:pdf)
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)
这是我需要执行的示例Curl请求,使用空手道POST请求
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'
我从服务器收到响应(具有preSignedUrl),并在功能文件中使用以下代码使用了
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>"
我尝试过
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]调试com.intuit.karate-请求:
I see the request format of Karate log as: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错误,因为字段值顺序不正确
I see the form data is not even passed in the actual requestBut I get a validation XML error from Amazon S3 for incorrect order of 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>
我希望204没有内容,并且文件将在S3存储桶中上传
I expect 204 No Content and the file to be uploaded the S3 bucket
推荐答案
我只是使用多部分字段而不是表单字段,所以它起作用了已更改:* form fields fieldData
到And multipart fields fieldData
I just used multipart fields instead of form fields and it workedChanged:* form fields fieldData
toAnd multipart fields fieldData
这篇关于如何使用预签名的URL以相同顺序将表单字段用于Amazon S3上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!