简体   繁体   English

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

[英]generate pre-signed object url using aws sdk for php 2

I googled for a solution to share a private S3 object using AWS SDK for PHP 2. 我用Google SDK for PHP 2搜索了一个共享私有S3对象的解决方案。

I can only find the solution for .Net, Java, and Visual Studio. 我只能找到.Net,Java和Visual Studio的解决方案。

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

I also want to generate this presigned url for just 15 minutes of expiry time. 我还希望在15分钟的到期时间内生成这个预先签名的网址。

Currently, there is a way to use the latest AWS SDK for PHP 2 to accomplish the above. 目前,有一种方法可以使用最新的PHP SDK for PHP 2来实现上述目标。

Read this . 这个

This link will show you 2 ways to do this. 该链接将向您显示两种方法。

Most common way is: 最常见的方式是:

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

The second way is to use the command object method which is reproduced below. 第二种方法是使用下面再现的命令对象方法。

// 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 will give you a string that looks something like this: $signedUrl会给你一个看起来像这样的字符串:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM