如何使用postdata preSigned Url调用Amazon S3存储桶以使用Karate上传文件 [英] How to call Amazon S3 bucket using postdata preSigned Url to upload a file using Karate

查看:61
本文介绍了如何使用postdata preSigned Url调用Amazon S3存储桶以使用Karate上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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)

这是我需要执行使用空手道POST请求的示例Curl请求

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

但是我从Amazon S3收到验证XML错误,因为字段值不正确

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>

我希望204没有内容,并且文件将在S3存储桶中上传

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

推荐答案

尝试此更改:

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

请阅读以下内容以获得更多说明: https://github.com/intuit/karate/tree/develop#multipart-file

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

除此之外,您似乎做对了所有事情.因此,这取决于您现在的调试技能.或给我们一种复制方法: https://github.com/intuit/karate/wiki/如何提交问题

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

这篇关于如何使用postdata preSigned Url调用Amazon S3存储桶以使用Karate上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆