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