Amazon S3 Library for Ruby


1. Install amazon s3 gem.

$gem install aws-s3

2. Connect with S3.

require 'aws/s3'

AWS::S3::Base.establish_connection!(
  :access_key_id     => 'key goes here',
  :secret_access_key => 'secret goes here'
)

3. Various operation on S3 buckets:

a) store an object on S3
S3Object.store('me.jpg', open('headshot.jpg'), 'photos')

b) More explicitly data
S3Object.store(
  'name of object',
  File.open('large-picture.jpg'),
  'name of bucket',
  :content_type => 'image/jpeg'
)

c) Fetch object from S3
picture = S3Object.find 'headshot.jpg', 'photos'

Cheers!

 
 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s