2

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 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.