【问题标题】:Amazon S3 PHP SDK pre-signed requestsAmazon S3 PHP SDK 预签名请求
【发布时间】:2015-06-02 17:44:40
【问题描述】:

我正在尝试使用 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 工作正常,权限设置为允许未经身份验证的用户。

【问题讨论】:

标签: php amazon-web-services amazon-s3


【解决方案1】:
$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

【讨论】:

    猜你喜欢
    • 2017-07-06
    • 1970-01-01
    • 2018-12-27
    • 2017-10-10
    • 1970-01-01
    • 2017-12-26
    • 2012-03-04
    • 2021-10-18
    • 1970-01-01
    相关资源
    最近更新 更多