我在谷歌上搜索了一个解决方案,使用 AWS 开发工具包 PHP 2 共享私有 S3 对象。
我只能找到.Net,Java和Visual Studio的解决方案。
http://docs.aws.amazon.com/AmazonS3/latest/dev/ShareObjectPreSignedURL.html
我还想生成这个预签名的 url,只有 15 分钟的到期时间。
目前,有一种方法可以使用适用于 PHP 2 的最新 AWS 开发工具包来完成上述工作。
阅读此内容。
此链接将向您展示 2 种方法。
最常见的方法是:
$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