簡體   English   中英

如何使用 postdata preSigned Url 調用 Amazon S3 存儲桶以使用空手道上傳文件

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

我有一個 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

但我從 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 存儲桶

試試這個改變:

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

閱讀此內容以獲得更多解釋: https://github.com/intuit/karate/tree/develop#multipart-file

除此之外,你似乎做的一切都是對的。 所以現在就看你的調試技巧了。 或者給我們一個復制的方法: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM