Reputation: 1314
I'm uploading a file to an S3 bucket for which I've created a Cloudfront distribution. I'm using the Aws\S3\S3Client
class.
After uploading with putObject
, the response object and the getObjectUrl
method both return the object's url as https://s3-eu-west-1.amazonaws.com/mybucket/path/myfile.jpg. I am trying to get the Cloudfront url which would be something like https://d111111111ck.cloudfront.net/path/myfile.jpg.
Is there any way to get this url directly, or do I have to build it from my distribution hostname and file path?
Upvotes: 4
Views: 7493
Reputation: 1520
I guess there's is no way to resolve an associated cloudfront url for the bucket
. Yes, It is!
CloudFront is a CDN caching. You did not need to get the URL to s3 bucket/file because CloudFront cares about this for you.
More details about AWS CloudFront here.
Follow the steps and see the step 24
. That's it!
Screenshots below:
Enjoy! :)
Upvotes: 1
Reputation: 21531
You won't get a cloudfront URL from S3, it's a different service. If your using putObject
then you already know the file path (value specified in Key
).
Just return the cloudfront URL in front of the file path e.g...
$filePath = '/path/file.jpg';
$client->putObject(array(
'Bucket' => 'mybucket',
'Key' => $filePath,
'SourceFile' => $fileSource,
'ACL' => 'public-read'
));
return 'https://d111111111ck.cloudfront.net' . $filePath;
Upvotes: 7