Zend Framework 101: Zend_Service_Amazon_S3
Using Objects Stored in Amazon S3 Buckets
Finally, let's look at how other users can access files you store in your Amazon S3 buckets. The name of the bucket maps directly to the following domain name to the following web addresses:
http://[bucketName].s3.amazonaws.com/[objectName]
http://s3.amazonaws.com/[bucketName]/[objectName]
Using our previous examples from this article, you can access the
my-file.txt
file at the following URLs:http://phpriot-test-bucket.s3.amazonaws.com/my-file.txt
http://s3.amazonaws.com/phpriot-test-bucket/my-file.txt
If we didn't set the permissions to be publicly readable, then it would not be possible for others to access your files.
You can now link to these files directly from your web pages, rather than hosting your files yourself. The following listing demonstrates how you might achieve this. It uses Amazon S3 for CSS, images, and for a file download link.
Listing 12 Using your Amazon S3 bucket on your web site (use-cdn.php)
$bucketName = 'my-company-bucket'; $cdnUrl = 'http://' . $bucketName . '.s3.amazonaws.com'; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Sample Amazon S3 CDN Usage Page</title> <link rel="stylesheet" href=" echo $cdnUrl /css/styles.css" type="text/css" media="all" /> </head> <body> <div> <img src=" echo $cdnUrl /images/logo.png" alt="My Logo" /> </div> <div> <a href=" echo $cdnUrl /assets/profile.pdf"> Download company profile </a> </div> </body> </html>
No comments:
Post a Comment