Skip to content

thomasalrin/s3

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

<img src=“travis-ci.org/qoobaa/s3.svg?branch=master” alt=“Build Status” />

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

It supports all S3 regions through the REST API.

gem install s3
require "s3"
service = S3::Service.new(:access_key_id => "...",
                          :secret_access_key => "...",

:host => “127.0.0.1”)

#=> #<S3::Service:...>
service.buckets
#=> [#<S3::Bucket:first-bucket>,
#    #<S3::Bucket:second-bucket>]
first_bucket = service.buckets.find("first-bucket")
#=> #<S3::Bucket:first-bucket>
new_bucket = service.buckets.build("newbucketname")
new_bucket.save(:location => :eu)

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

Please refer to: docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html for more information about bucket name restrictions.

first_bucket.objects
#=> [#<S3::Object:/first-bucket/lenna.png>,
#    #<S3::Object:/first-bucket/lenna_mini.png>]
object = first_bucket.objects.find("lenna.png")
#=> #<S3::Object:/first-bucket/lenna.png>
object.content_type
#=> "image/png"
object.content
#=> "\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00..."
object.destroy
#=> true
new_object = bucket.objects.build("bender.png")
#=> #<S3::Object:/synergy-staging/bender.png>

new_object.content = open("bender.png")

new_object.save
#=> true

Please note that new objects are created with “private” ACL by default.

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

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

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

Check the example in this gist, which describes how to use a simple form element to upload files directly to S3.

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%