Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rest 如何使用AWS API网关代理与S3集成上传图像_Rest_Amazon Web Services_Amazon S3_Postman_Aws Api Gateway - Fatal编程技术网

Rest 如何使用AWS API网关代理与S3集成上传图像

Rest 如何使用AWS API网关代理与S3集成上传图像,rest,amazon-web-services,amazon-s3,postman,aws-api-gateway,Rest,Amazon Web Services,Amazon S3,Postman,Aws Api Gateway,在设置我的API以上载文件后,我意识到有一种特殊情况,即您希望上载图片(jpg),您在API中定义了二进制支持,但出现以下错误: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details. The

在设置我的API以上载文件后,我意识到有一种特殊情况,即您希望上载图片(jpg),您在API中定义了二进制支持,但出现以下错误:

The request signature we calculated does not match the signature you 
provided. Check your AWS Secret Access Key and signing method. 
Consult the service documentation for details.
The Canonical String for this request should have been 
'PUT /test/vi-dummy-bucket/testImg2.jpg
content-type:application/x-www-form-urlencoded
host:qhweyos7z2.execute-api.us-west-1.amazonaws.com
x-amz-date:20170808T154441Z
x-amz-security-token: // security token string no quotes
content-type;host;x-amz-date;x-amz-security-token 5fa90f0 ...'
The String-to-Sign should have been
'AWS4-HMAC-SHA256\n20170808T154441Z
20170808/us-west-1/execute-api/aws4_request
f7a38fa ...'
奇怪的是,上传简单的文本文件使用完全相同的api调用,那么我唯一需要改变的就是

Content-Type 'text/plain'
并在请求的原始部分写入文本

不确定这是内容类型问题还是请求正文问题,如果我将所有内容都保持在工作状态(正文中的文本/纯文本和文本),只需将正文更改为二进制并设置图像,则会出现上述错误

  • 我的API网关位于美国西部1区
  • 我的S3桶在美国东部1区
我使用的请求是:

PUT /test/vi-dummy-bucket/testImg2.jpg HTTP/1.1
Host: qhwe7z2.execute-api.us-west-1.amazonaws.com
Content-Type: application/x-www-form-urlencoded
X-Amz-Security-Token: FQoDYX ... 
X-Amz-Date: 20170808T154441Z
Authorization: AWS4-HMAC-SHA256 
Credential=ASIAJICO6JFTJWN7A/20170808/us-west-1/execute-
api/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-
security-token,   
Signature=6a792 ... Cache-Control: no-cache
Postman-Token: e9d1f730-f50b-7e27-70cc-c15a138d8cc6
(二进制图像)

这是请求的另一个版本(相同错误):

---更新---

使用生成的SDK手动实现sigV4 SIGNING后,签名不再是问题

剩下的唯一问题是,生成的SDK只接受一个字符串作为“body”,因此我必须将该文件转换为二进制字符串。然后它正确地通过,并在S3中创建了一个文件,但现在大小是原来的两倍,并且它不可见,就好像二进制字符串没有转换回二进制文件一样。太令人沮丧了


顺便说一句,我已经尝试了通过PASSTHROUGH并将\u转换为\u二进制。

更新:看起来这可能与邮递员中的已知错误有关。以下是一个相关的SO问题供参考:

这是给邮递员的错误报告:

如果使用备用rest客户端和/或命令行实用程序,如
curl
httpie
,请求是否有效


如果您配置了二进制支持,您可能应该设置
内容类型
,以匹配您正在发送的二进制内容


根据您发布的内容,您正在使用
内容类型应用程序/x-www-form-urlencoded
发送二进制内容,但如果正文实际上是一个二进制
jpeg
文件,我希望您应该发送
内容类型图像/jpeg

我尝试了不同内容类型的相同内容,这只是我最后一次尝试^^
PUT /test/vi-dummy-bucket/testImg2.jpg HTTP/1.1
Content-Type: image/jpeg
x-amz-security-token: FQoDY ... 
x-amz-date: 20170808T190134Z
Authorization: AWS4-HMAC-SHA256 
Credential=ASIAIZSP5YKVLJ3GVVQA/20170808/us-west-1/execute-
api/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-
security-token, 
Signature=b2324 ...
Host: qhos7z2.execute-api.us-west-1.amazonaws.com
Connection: close
User-Agent: Paw/3.1.2 (Macintosh; OS X/10.12.6) GCDHTTPRequest
Content-Length: 823236