【问题标题】:generate pre-signed object url using aws sdk for php 2使用 aws sdk for php 2 生成预签名对象 url
【发布时间】:2013-10-04 04:25:43
【问题描述】:

我在 Google 上搜索了一个使用 AWS SDK for PHP 2 共享私有 S3 对象的解决方案。

我只能找到 .Net、Java 和 Visual Studio 的解决方案。

http://docs.aws.amazon.com/AmazonS3/latest/dev/ShareObjectPreSignedURL.html

我还想在 15 分钟的有效期内生成这个预签名的 url。

【问题讨论】:

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


    【解决方案1】:

    目前,有一种方法可以使用最新的 AWS SDK for PHP 2 来完成上述工作。

    阅读this

    此链接将向您展示两种方法。

    最常见的方式是:

    $signedUrl = $client->getObjectUrl($bucket, 'data.txt', '+15 minutes');
    

    第二种方法是使用下面复制的命令对象方法。

    // Get a command object from the client and pass in any options
    // available in the GetObject command (e.g. ResponseContentDisposition)
    $command = $client->getCommand('GetObject', array(
        'Bucket' => $bucket,
        'Key' => 'data.txt',
        'ResponseContentDisposition' => 'attachment; filename="data.txt"'
    ));
    
    // Create a signed URL from the command object that will last for
    // 15 minutes from the current time
    $signedUrl = $command->createPresignedUrl('+15 minutes');
    

    $signedUrl 会给你一个看起来像这样的字符串:

    https://bucketname.s3.amazonaws.com/keytothefile.ext?AWSAccessKeyId=AASDASDFDFGTSSYCQ&Expires=1380861181&Signature=eD6qtV81278nmashdkp0huURXc%3D

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      • 2017-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多