使用aws sdk为php 2生成预签名对象url

Kim*_*cks 2 php amazon-s3 amazon-web-services

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

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

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

我还希望在15分钟的到期时间内生成这个预先签名的网址.

Kim*_*cks 7

目前,有一种方法可以使用最新的PHP SDK for PHP 2来实现上述目标.

这个.

此链接将向您显示两种方法.

最常见的方式是:

$signedUrl = $client->getObjectUrl($bucket, 'data.txt', '+15 minutes');
Run Code Online (Sandbox Code Playgroud)

第二种方法是使用下面再现的命令对象方法.

// 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');
Run Code Online (Sandbox Code Playgroud)

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

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