class RJack::JetS3t::S3Bucket

Facade over org.jets3t.service.model.S3Bucket

Attributes

default_acl[RW]

Default ACL for put

host_prefix[RW]

Hostname/prefix used use when composing HTTP access URLs.

jbucket[R]

The underlying org.jets3t.service.model.S3Bucket

service[R]

The S3Service in which this bucket resides

Public Class Methods

new( service, jbucket, opts = {} ) click to toggle source

New bucket wrapper

Parameters

service<S3Service>

S3Service in which this bucket resides

jbucket<org.jets3t.service.model.S3Bucket>

the bucket

Options (opts)

:host_prefix<~to_s>

Host name/prefix to use when composing access URLs. (Default: s3.amazonaws.com/bucket-name)

:default_acl<AccessControlList>

Default ACL for put

(Default: AccessControlList::REST_CANNED_PUBLIC_READ)

Raises

:S3ServiceException

From JetS3t

:RuntimeError

On failure to provide required options

# File lib/rjack-jets3t/s3_bucket.rb, line 53
def initialize( service, jbucket, opts = {} )
  @service = service
  @jbucket = jbucket
  @host_prefix   = ( opts[ :host_prefix ] ||
                     [ 's3.amazonaws.com', jbucket.name ].join( '/' ) )
  @default_acl = ( opts[ :default_acl ] ||
                   AccessControlList::REST_CANNED_PUBLIC_READ )
end

Public Instance Methods

delete( name ) click to toggle source

Delete object with the given name in this bucket

Raises

:S3ServiceException

From JetS3t

# File lib/rjack-jets3t/s3_bucket.rb, line 107
def delete( name )
  @service.jservice.delete_object( @jbucket, name )
end
get( key ) { |obj| ... } click to toggle source

Get and yield S3Object from this S3 bucket for the given key. Ensures that on return from block, the objects date_input_stream will be closed.

Raises

:S3ServiceException

From JetS3t

# File lib/rjack-jets3t/s3_bucket.rb, line 93
def get( key )
  obj = @service.jservice.get_object( @jbucket.name, key )
  yield obj
  nil
ensure
  if obj
    din = obj.data_input_stream
    din.close if din
 end
end
name() click to toggle source

Bucket name

# File lib/rjack-jets3t/s3_bucket.rb, line 63
def name
  @jbucket.name
end
put( key, mime_type, rbytes = nil ) { |obj| ... } click to toggle source

Put object in this S3 bucket at the given key. Yields S3Object for setting content, acl or other overrides if given. Optional data may be passed as a Ruby String which will be converted to java_bytes. Returns external HTTP url using :host_prefix

Raises

:S3ServiceException

From JetS3t

# File lib/rjack-jets3t/s3_bucket.rb, line 74
def put( key, mime_type, rbytes = nil )
  if rbytes
    rbytes = rbytes.to_java_bytes if rbytes.respond_to?( :to_java_bytes )
    obj = S3Object.new( key, rbytes )
  else
    obj = S3Object.new( @jbucket, key )
  end
  obj.content_type = mime_type
  obj.acl = @default_acl
  yield obj if block_given?
  @service.jservice.put_object( @jbucket, obj )
  "http://%s/%s" % [ @host_prefix, key ]
end