Class: AWS::S3::MultipartUpload
- Inherits:
-
Object
- Object
- AWS::S3::MultipartUpload
- Defined in:
- lib/aws/s3/multipart_upload.rb
Overview
Represents a multipart upload to an S3 object. See S3Object#multipart_upload for a convenient way to initiate a multipart upload.
Instance Attribute Summary collapse
-
#id ⇒ String
(also: #upload_id)
readonly
Returns the upload id.
-
#object ⇒ S3Object
readonly
Returns the object this upload is intended for.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Returns true if both multipart uploads represent the same object and upload.
-
#abort ⇒ nil
(also: #delete, #cancel)
Aborts the upload.
-
#aborted? ⇒ Boolean
True if the upload has been aborted.
-
#add_part(data_or_options, options = {}) ⇒ Object
Uploads a part.
- #bucket ⇒ Object
-
#close ⇒ S3Object, ObjectVersion
Completes the upload or aborts it if no parts have been uploaded yet.
-
#complete(*parts) ⇒ S3Object, ObjectVersion
Completes the upload by assembling previously uploaded parts.
-
#exists? ⇒ Boolean
True if the upload exists.
-
#initiator ⇒ Object
The upload initiator.
-
#owner ⇒ Object
The upload owner.
-
#parts ⇒ UploadedPartCollection
A collection representing the parts that have been uploaded to S3 for this upload.
-
#reduced_redundancy? ⇒ Boolean
True if the uploaded object will be stored with reduced redundancy.
-
#storage_class ⇒ Symbol
The class of storage used to store the uploaded object.
Instance Attribute Details
#id ⇒ String (readonly) Also known as: upload_id
Returns the upload id.
50 51 52 |
# File 'lib/aws/s3/multipart_upload.rb', line 50 def id @id end |
#object ⇒ S3Object (readonly)
Returns the object this upload is intended for.
55 56 57 |
# File 'lib/aws/s3/multipart_upload.rb', line 55 def object @object end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Returns true if both multipart uploads represent the same object and upload.
59 60 61 62 63 |
# File 'lib/aws/s3/multipart_upload.rb', line 59 def ==(other) other.kind_of?(MultipartUpload) and other.object == object and other.id == id end |
#abort ⇒ nil Also known as: delete, cancel
Aborts the upload. After a multipart upload is aborted, no additional parts can be uploaded using that upload ID. The storage consumed by any previously uploaded parts will be freed. However, if any part uploads are currently in progress, those part uploads might or might not succeed. As a result, it might be necessary to abort a given multipart upload multiple times in order to completely free all storage consumed by all parts.
115 116 117 118 119 |
# File 'lib/aws/s3/multipart_upload.rb', line 115 def abort client.abort_multipart_upload(base_opts) @aborted = true nil end |
#aborted? ⇒ Boolean
Returns True if the upload has been aborted.
125 126 127 |
# File 'lib/aws/s3/multipart_upload.rb', line 125 def aborted? @aborted end |
#add_part(data, options = {}) ⇒ Object #add_part(options) ⇒ Object
Uploads a part.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/aws/s3/multipart_upload.rb', line 184 def add_part(, = {}) if .kind_of?(Hash) = base_opts.merge() else = base_opts.merge(:data => ) end .merge!() unless [:part_number] @increment_mutex.synchronize do [:part_number] = (@last_part += 1) end end part_number = [:part_number] resp = client.upload_part() @completed_mutex.synchronize do @completed_parts[part_number] = { :part_number => part_number, :etag => resp.etag } end UploadedPart.new(self, part_number) end |
#bucket ⇒ Object
42 43 44 |
# File 'lib/aws/s3/multipart_upload.rb', line 42 def bucket object.bucket end |
#close ⇒ S3Object, ObjectVersion
Completes the upload or aborts it if no parts have been uploaded yet. Does nothing if the upload has already been aborted.
260 261 262 263 264 265 266 267 |
# File 'lib/aws/s3/multipart_upload.rb', line 260 def close return if aborted? if completed_parts.empty? abort else complete end end |
#complete(*parts) ⇒ S3Object, ObjectVersion
Completes the upload by assembling previously uploaded parts.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/aws/s3/multipart_upload.rb', line 216 def complete(*parts) parts = parts.flatten case parts.first when :remote_parts complete_opts = get_complete_opts when :local_parts, nil complete_opts = base_opts.merge(:parts => completed_parts) else part_numbers = parts.map do |part| case part when Integer part when UploadedPart raise ArgumentError.new("cannot complete an upload with parts "+ "from a different upload") unless part.upload == self part.part_number else raise ArgumentError.new("expected number or UploadedPart") end end complete_opts = get_complete_opts(part_numbers) end raise "no parts uploaded" if complete_opts[:parts].empty? resp = client.complete_multipart_upload(complete_opts) if resp.version_id ObjectVersion.new(object, resp.version_id) else object end end |
#exists? ⇒ Boolean
Returns True if the upload exists.
68 69 70 71 72 73 74 |
# File 'lib/aws/s3/multipart_upload.rb', line 68 def exists? client.list_parts(base_opts) rescue Errors::NoSuchUpload => e false else true end |
#initiator ⇒ Object
Returns The upload initiator. This object will have :id
and :display_name
methods; if the initiator is an IAM user, the :id
method will return the ARN of the user, and if the initiator is an AWS account, this method will return the same data as #owner.
81 82 83 |
# File 'lib/aws/s3/multipart_upload.rb', line 81 def initiator client.list_parts(base_opts).initiator end |
#owner ⇒ Object
Returns The upload owner. This object will have :id
and :display_name
methods.
87 88 89 |
# File 'lib/aws/s3/multipart_upload.rb', line 87 def owner client.list_parts(base_opts).owner end |
#parts ⇒ UploadedPartCollection
Returns A collection representing the parts that have been uploaded to S3 for this upload.
271 272 273 |
# File 'lib/aws/s3/multipart_upload.rb', line 271 def parts UploadedPartCollection.new(self) end |
#reduced_redundancy? ⇒ Boolean
Returns True if the uploaded object will be stored with reduced redundancy.
102 103 104 |
# File 'lib/aws/s3/multipart_upload.rb', line 102 def reduced_redundancy? storage_class == :reduced_redundancy end |
#storage_class ⇒ Symbol
Returns The class of storage used to store the uploaded object. Possible values:
-
:standard
-
:reduced_redundancy?
.
96 97 98 |
# File 'lib/aws/s3/multipart_upload.rb', line 96 def storage_class client.list_parts(base_opts).storage_class.downcase.to_sym end |