• Stars
    star
    258
  • Rank 158,189 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

S3

<img src=“https://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.

Installation

gem install s3

Usage

Initialize the service

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

List buckets

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

Find bucket

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

or

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

service.bucket("first-bucket") does not check whether a bucket with the name "first-bucket" exists, but it also does not issue any HTTP requests. Thus, the second example is much faster than buckets.find. You can use first_bucket.exists? to check whether the bucket exists after calling service.bucket.

Create 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.

List objects in a bucket

first_bucket.objects
#=> [#<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)

object.content_type
#=> "image/png"

Access object content (downloads the object)

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

Delete an object

object.destroy
#=> true

Create an object

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

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

new_object.acl = :public_read

new_object.save
#=> true

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

Request access to a private object

Returns a temporary url to the object that expires on the timestamp given. Defaults to one hour expire time.

new_object.temporary_url(Time.now + 1800)

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 => :public_read)

Upload file direct to amazon

Rails 3

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

See also

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

More Repositories

1

fakturama

Wystawiaj faktury za darmo i bez ograniczeń
JavaScript
77
star
2

xxx

Porn of the day
Ruby
56
star
3

vcard

Vcard support extracted from Vpim
Ruby
52
star
4

javascript_i18n

Dead simple JavaScript i18n tool for your Rails application
Ruby
32
star
5

pioneers

Pioneers - web game based on The Settlers of Catan board game
JavaScript
29
star
6

ruby-electric

Improved ruby-electric mode
Emacs Lisp
27
star
7

magic

Determine file type and encoding using "magic" numbers
Ruby
26
star
8

sms

Simple Message Sending application
JavaScript
26
star
9

sqlite3

Ruby
13
star
10

to_hash

ToHash module for easy data serialization (using JSON, XML, etc.)
Ruby
7
star
11

sqs

Amazon's Simple Queue Service access library
Ruby
5
star
12

bridge

Useful contract bridge utilities - deal generator, id to deal and deal to id conversion
Ruby
5
star
13

bridge-ember

Bridge written in Ember.js (hopefully)
Ruby
4
star
14

sane-ffi

SANE bindings
Ruby
4
star
15

proxies

Proxies can even proxy other proxies
Ruby
4
star
16

lol

LOLCODE interpreter written in Ruby
Ruby
4
star
17

ficha

Ficha
JavaScript
3
star
18

beaconpush

Gem for adding Beacon support into your application
Ruby
3
star
19

active_model-session

Lightweight session model implemented on top of ActiveModel::Model
Ruby
3
star
20

dissertation

TeX
2
star
21

bridge.js

JavaScript
2
star
22

ruby-mode

Emacs Lisp
2
star
23

hstore_attributes

Provides methods like hstore_reader or hstore_writer for accessing your Hstore data like any other attributes.
Ruby
2
star
24

active_model-password_reset

Simple password reset model implemented on top of ActiveModel::Model
Ruby
2
star
25

double_trouble

Adds nonces to your Rails’ forms.
Ruby
2
star
26

s3_upload_form

S3 upload form for direct S3 file uploading
Ruby
2
star
27

polish-to-words

JavaScript library to convert a number to its word representation in Polish language
JavaScript
2
star
28

gossip

Simple chat using SSE written in Go language.
Go
2
star
29

active_model-email_confirmation

Simple email confirmation model implemented on top of ActiveModel::Model
Ruby
2
star
30

active_model-password

Simple password model implemented on top of ActiveModel::Model
Ruby
1
star
31

inbox

Ruby
1
star
32

depthsensor-code

C
1
star
33

callstack

Where is my Call Stack?!?
JavaScript
1
star
34

bombs

CSS
1
star
35

beskid-slaski

A simple offline map application for mobile devices
JavaScript
1
star
36

depthsensor-pcb

1
star
37

rails-way-tm

Ruby
1
star
38

dissertation-slides

1
star
39

nbp-yql

JavaScript library to fetch exchange rates from National Bank of Poland through YQL
JavaScript
1
star
40

oauth-example

OAuth working example
Ruby
1
star
41

.files

My dotfiles managed by GNU Stow
Shell
1
star
42

slaskit.pl

Śląsk IT web page
JavaScript
1
star
43

bridge-utils

JavaScript
1
star
44

cents

Small JavaScript library for parsing and formatting cents
JavaScript
1
star