I am learning Amazon S3 using S3 PHP Class. I have uploaded my all files to my S3 bucket, now I want to create links for each available file in my bucket.
Will the following function work for me?
public static function getAuthenticatedURL($bucket, $uri, $lifetime, $hostBucket = false, $https = false)
{
}
$s3 = new S3('access-key', 'secret-key');
$s3->getAuthenticatedURL($bucket, $uri, $lifetime, $hostBucket = false, $https = false);
Or another function like get_object_url
, but get_object_url()
not in my S3 class.
I am using Undesigned's Amazon S3 PHP class.
To generate a presigned URL using the AWS Management ConsoleSign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that contains the object that you want a presigned URL for.
You can download an object from an S3 bucket in any of the following ways: Select the object and choose Download or choose Download as from the Actions menu if you want to download the object to a specific folder. If you want to download a specific version of the object, select the Show versions button.
aws s3 sync s3://mybucket . will download all the objects in mybucket to the current directory. This will download all of your files using a one-way sync. It will not delete any existing files in your current directory unless you specify --delete , and it won't change or delete any files on S3.
The following patterns are valid for constructing S3 URLs:
http(s)://<bucket>.s3.amazonaws.com/<object>
http(s)://s3.amazonaws.com/<bucket>/<object>
If you want the public to access the bucket, it is as simple as
http://[YourBucketName].s3.amazonaws.com/[YourFileName]
So long as you set permissions correctly.
If you're worried about download abuse, you'll want an authenticated URL (which I guess you want from your code sammple). In which case, I suggest you use the Amazon SDK: http://aws.amazon.com/sdkforphp/ as it contains examples of what you need.
$s3->getObjectUrl($bucket, $filename, '5 minutes');
Docs: http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.S3.S3Client.html#_getObjectUrl
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With