Class: AWS::S3::ObjectUploadCollection

Inherits:
Object
  • Object
show all
Includes:
Core::Model, Enumerable
Defined in:
lib/aws/s3/object_upload_collection.rb

Overview

Represents uploads in progress for a single object.

Examples:

Cancel all uploads for an object

object.multipart_uploads.each(&:abort)

Get an upload by ID

object.multipart_uploads[id]

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from Core::Model

#client, #config_prefix, #inspect

Constructor Details

#initialize(object, opts = {}) ⇒ ObjectUploadCollection

Returns a new instance of ObjectUploadCollection.



33
34
35
36
37
38
39
# File 'lib/aws/s3/object_upload_collection.rb', line 33

def initialize(object, opts = {})
  @all_uploads =
    MultipartUploadCollection.new(object.bucket).
    with_prefix(object.key)
  @object = object
  super
end

Instance Attribute Details

#objectS3Object (readonly)

Returns The object to which the uploads belong.

Returns:

  • (S3Object)

    The object to which the uploads belong.



30
31
32
# File 'lib/aws/s3/object_upload_collection.rb', line 30

def object
  @object
end

Instance Method Details

#[](id) ⇒ MultipartUpload

Returns An object representing the upload with the given ID.

Parameters:

  • id (String)

    The ID of an upload to get.

Returns:

  • (MultipartUpload)

    An object representing the upload with the given ID.



70
71
72
# File 'lib/aws/s3/object_upload_collection.rb', line 70

def [] id
  MultipartUpload.new(object, id)
end

#create(options = {}) ⇒ Object

Creates a new multipart upload. It is usually more convenient to use S3Object#multipart_upload.



43
44
45
46
47
48
49
50
51
52
# File 'lib/aws/s3/object_upload_collection.rb', line 43

def create(options = {})
  options[:storage_class] = :reduced_redundancy if
    options.delete(:reduced_redundancy)
  initiate_opts = {
    :bucket_name => object.bucket.name,
    :key => object.key
  }.merge(options)
  id = client.initiate_multipart_upload(initiate_opts).upload_id
  MultipartUpload.new(object, id)
end

#each(options = {}) {|upload| ... } ⇒ nil

Iterates the uploads in the collection.

Yield Parameters:

Returns:

  • (nil)


59
60
61
62
63
64
# File 'lib/aws/s3/object_upload_collection.rb', line 59

def each(options = {}, &block)
  @all_uploads.each(options) do |upload|
    yield(upload) if upload.object.key == @object.key
  end
  nil
end