我正在尝试使用S3 PHP SDK生成预先签名的请求,如下所示:
$s3Client = Aws\S3\S3Client::factory([
'credentials' => new Aws\Common\Credentials\Credentials('my-access-code', 'xxx')
]);
$command = $s3Client->getCommand('GetObject', [
'Bucket' => 'my-bucket-name',
'Key' => 'awesome-cat-image.png',
]);
$signedUrl = $command->createPresignedUrl('+10 minutes');
但是当我转到URL时,我收到一条错误说:
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>
The request signature we calculated does not match the signature you provided. Check your key and signing method.
</Message>
<AWSAccessKeyId>xxx</AWSAccessKeyId>
<StringToSign>GET 1422564095 /my-bucket-name/awesome-cat-image.png</StringToSign>
<SignatureProvided>xxx</SignatureProvided>
<StringToSignBytes>
xxx
</StringToSignBytes>
<RequestId>xxx</RequestId>
<HostId>
xxx
</HostId>
</Error>
访问https://my-bucket-name.s3.amazonaws.com/awesome-cat-image.png可以正常工作,权限设置为允许未经过身份验证的用户。
答案 0 :(得分:0)
$cmd = $s3Client->getCommand('GetObject', [
'Bucket' => 'my-bucket',
'Key' => 'testKey'
]);
$request = $s3Client->createPresignedRequest($cmd, '+20 minutes');
// Get the actual presigned-url
$presignedUrl = (string) $request->getUri();
您可以在http://docs.aws.amazon.com/aws-sdk-php/v3/guide/service/s3-presigned-url.html
找到更多详细信息