Skip to content
This repository

Library for accessing S3 objects and buckets, supports EU and US buckets

fixed tests

latest commit 386361c1b0
Kuba Kuźma authored
Octocat-spinner-32 lib fixed tests February 21, 2014
Octocat-spinner-32 test updated gems, bumped version January 28, 2014
Octocat-spinner-32 .gitignore using bundler now September 04, 2010
Octocat-spinner-32 Gemfile refactoring December 16, 2011
Octocat-spinner-32 Gemfile.lock fixed tests February 21, 2014
Octocat-spinner-32 LICENSE refactoring June 29, 2009
Octocat-spinner-32 README.rdoc Update README.rdoc April 03, 2013
Octocat-spinner-32 Rakefile updated gems, bumped version January 28, 2014
Octocat-spinner-32 s3.gemspec updated gems, bumped version January 28, 2014


S3 library provides access to Amazon’s Simple Storage Service.

It supports both: European and US buckets through the REST API.


gem install s3


Initialize the service

require "s3"
service = => "...",
                          :secret_access_key => "...")
#=> #<S3::Service:...>

List buckets

#=> [#<S3::Bucket:first-bucket>,
#    #<S3::Bucket:second-bucket>]

Find bucket

first_bucket = service.buckets.find("first-bucket")
#=> #<S3::Bucket:first-bucket>

Create bucket

new_bucket ="newbucketname") => :eu)

Remember that bucket name for EU can't include “_” (underscore).

Please refer to: for more information about bucket name restrictions.

List objects in a bucket

#=> [#<S3::Object:/first-bucket/lenna.png>,
#    #<S3::Object:/first-bucket/lenna_mini.png>]

Find object in a bucket

object = first_bucket.objects.find("lenna.png")
#=> #<S3::Object:/first-bucket/lenna.png>

Access object metadata (cached from find)

#=> "image/png"

Access object content (downloads the object)

#=> "\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00..."

Delete an object

#=> true

Create an object

new_object ="bender.png")
#=> #<S3::Object:/synergy-staging/bender.png>

new_object.content = open("bender.png")
#=> true

Please note that new objects are created with “public-read” ACL by default.

Fetch ACL

object = bucket.objects.find('lenna.png')
object.request_acl # or bucket.request_acl

This will return hash with all users/groups and theirs permissions

Modify ACL

object = bucket.objects.find("lenna.png")
object.copy(:key => "lenna.png", :bucket => bucket, :acl => :private)

Upload file direct to amazon

Rails 3

To do that you just send file using proper form direct to amazon. You can create simple halper for that, for example like this one:

See also


Copyright © 2009 Jakub Kuźma, Mirosław Boruta. See LICENSE for details.

Something went wrong with that request. Please try again.