2
votes

I googled for a solution to share a private S3 object using AWS SDK for PHP 2.

I can only find the solution for .Net, Java, and Visual Studio.

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.

1

1 Answers

7
votes

Currently, there is a way to use the latest AWS SDK for PHP 2 to accomplish the above.

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:

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