使用PHP SDK使用MD5哈希创建AWS S3预签名URL

时间:2017-05-03 22:36:26

标签: php amazon-s3

我无法构建包含MD5哈希的S3预签名网址。以下是我使用的代码:

$s3 = new Aws\S3\S3Client( ... );
$md5Hash = "YmEwMWVmNzE5MjI3YzdjNmI0ZjYzNGMxZWI1MmY1Y2U=";
$cmd = $s3->getCommand('PutObject', [
                            'Bucket' => $bucket,
                            'Key'    => $key,
                            'Content-MD5' => $md5Hash,
                            'ContentType' => $contentType,
                            'Body'        => ''    
                        ]);

$request = $s3->createPresignedRequest($cmd, '+5 minutes');
$presignedUrl = (string)$request->getUri();  

结果presignedURL看起来像:

http://s3-external-1.amazonaws.com/ {桶} / {键} X-AMZ-内容-SHA256 = UNSIGNED-PAYLOAD&安培; X-AMZ-算法= AWS4-HMAC-SHA256&安培; X-AMZ-凭证= AKIAIWC7FFD2T3NCEUNQ%2F20170503% 2Fus - 东 - 1%2Fs3%2Faws4_request&安培; X-AMZ-日期= 20170503T215723Z&安培; X-AMZ-SignedHeaders =宿主安培; X-AMZ-过期= 3000&安培; X-AMZ-签名= ca61d80dcfee351e7ee8440a47c5007f1bc905ddc8229077abddab9c39412dc7

当我将Content-MD5哈希添加到我的PUT请求时,我收到一个错误,表明MD5标题没有签名:

AccessDenied - 请求中存在未签名的标头 HeadersNotSigned - content-md5

任何帮助表示赞赏!

0 个答案:

没有答案