Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [56]

By Root 673 0
though note that the automated file renaming it does makes it less useful if you’re using S3 for web development. I’m going to use S3Fox as an example, mostly because it’s cross-platform.

After you’ve installed the Add-on and restarted Firefox, you’ll find a new “S3 Organizer” entry in the Tools menu, as shown in Figure 5-5.

Figure 5-5. S3 Organizer in Firefox’s Tools menu

Selecting that item will open the S3 Organizer, and when you open it for the first time, it will prompt you to enter your account info. Click on the “Manage Accounts” item in the top-left corner of the S3 Organizer window to open the Accounts window (Figure 5-6), into which you should carefully place your S3 credentials.

Figure 5-6. S3 Organizer account preferences

Clicking “Close” will close the Accounts window and should connect you to your S3 account on the right side of the S3 Organizer window (Figure 5-7).

Figure 5-7. S3Fox Organizer window

Buckets of files


S3 is essentially a flat file system, in that it doesn’t support nested hierarchies of folders. You can create “buckets” (which are basically folders), but you can’t put them inside of each other. We’re going to create a new bucket first, and you should do this for each of the apps for which you want to store files on S3. If your app’s name is “Jay’s Super Cool Facebook App,” you might create a bucket called “jay.super.cool.app” (you’re only allowed to use lowercase letters, and you never want to put spaces into filenames on servers). Click on the “Create Directory” button above the file list on the right (it’s the little blue folder with the spark of life), and then name your new bucket (Figure 5-8).

Don’t be confused by the fact that the button is called “Create Directory” and that the dialog box uses the terms “Folder” and “Bucket” interchangeably. You can now upload any files you’d like, either by selecting them on the left and clicking the blue arrow, or by dragging and dropping from right to left.

Figure 5-8. S3Fox new bucket

As a final step, you’ll need to edit the permissions on your new bucket to allow “Everyone” to read the files, which you can do by selecting it in the list and clicking on the “Edit ACL” button (the Access Control List—the paper and pencil icon). Click on the red “X” in the Everyone/Read box to turn it into a green checkmark, turn on the “Apply to subfolders” checkbox, and then click Save (Figure 5-9).

Figure 5-9. S3Fox ACL

That should set the permissions of everything in your new bucket to match. You can now embed those images right in your HTML (or serve up PDFs, embed videos, etc.) by using the URL of your bucket:

Interacting with S3’s API


Adding files to S3 manually is great if your app has a small number of images or media files, but what about handling user-generated content uploads? A very popular app might have a million users, and if 10% of them are active every day and a quarter of those upload a 100k image, you’re looking at about 2 GB a day in new data. You certainly don’t want to have to upload that by hand!

There are a number of different ways to interact with S3 via the AWS API, including some great Client Libraries for different languages:

Neurofuzzy’s Amazon PHP class

http://neurofuzzy.net/2006/03/17/amazon-s3-php-class/

Edoceo, Inc.’s phps3tk

http://edoceo.com/creo/phps3tk

Undesigned’s Amazon S3 PHP class

http://undesigned.org.za/2007/10/22/amazon-s3-php-class

“How to Serve Static Files From Amazon’s S3” from the Ruby on Rails wiki

http://wiki.rubyonrails.org/rails/pages/howtoservestaticfilesfromamazonss3

JetS3t, an open source Java toolkit for Amazon S3

http://jets3t.s3.amazonaws.com/downloads.html

Amazonian Backends: Hosting on Elastic Cloud Computing


Problem


I want to make sure my app is able to scale up really quickly to meet demand. I’ve heard that Amazon’s Elastic Cloud Computing (EC2) service lets me add on servers as I need them, really cheaply. How do I host my app there?

Solution


As Amazon

Return Main Page Previous Page Next Page

®Online Book Reader