Class: Aws::S3::ObjectSummary
- Inherits:
-
Object
- Object
- Aws::S3::ObjectSummary
- Extended by:
- Deprecations
- Defined in:
- lib/aws-sdk-s3/object_summary.rb,
lib/aws-sdk-s3/customizations/object_summary.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
- #bucket_name ⇒ String
-
#etag ⇒ String
The entity tag is an MD5 hash of the object.
- #key ⇒ String
-
#last_modified ⇒ Time
The date the Object was Last Modified.
-
#owner ⇒ Types::Owner
The owner of the object.
-
#size ⇒ Integer
(also: #content_length)
Size in bytes of the object.
-
#storage_class ⇒ String
The class of storage used to store the object.
Actions collapse
- #copy_from(source, options = {}) ⇒ Types::CopyObjectOutput
- #delete(options = {}) ⇒ Types::DeleteObjectOutput
- #get(options = {}, &block) ⇒ Types::GetObjectOutput
- #initiate_multipart_upload(options = {}) ⇒ MultipartUpload
- #put(options = {}) ⇒ Types::PutObjectOutput
- #restore_object(options = {}) ⇒ Types::RestoreObjectOutput
Associations collapse
- #acl ⇒ ObjectAcl
- #bucket ⇒ Bucket
- #identifiers ⇒ Object deprecated private Deprecated.
- #multipart_upload(id) ⇒ MultipartUpload
- #object ⇒ Object
- #version(id) ⇒ ObjectVersion
Instance Method Summary collapse
- #client ⇒ Client
- #copy_to(target, options = {}) ⇒ Object
-
#data ⇒ Types::Object
Returns the data for this ObjectSummary.
-
#data_loaded? ⇒ Boolean
Returns ‘true` if this resource is loaded.
-
#download_file(destination, options = {}) ⇒ Boolean
Returns ‘true` when the file is downloaded without any errors.
-
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the ObjectSummary exists.
-
#initialize(*args) ⇒ ObjectSummary
constructor
A new instance of ObjectSummary.
- #load ⇒ Object (also: #reload) private
- #move_to(target, options = {}) ⇒ void
- #presigned_post(options = {}) ⇒ PresignedPost
- #presigned_url(http_method, params = {}) ⇒ String
- #public_url(options = {}) ⇒ String
-
#upload_file(source, options = {}) ⇒ Boolean
Returns ‘true` when the object is uploaded without any errors.
-
#upload_stream(options = {}, &block) ⇒ Boolean
Returns ‘true` when the object is uploaded without any errors.
-
#wait_until(options = {}) {|resource| ... } ⇒ Resource
deprecated
Deprecated.
Use [Aws::S3::Client] #wait_until instead
- #wait_until_exists(options = {}, &block) ⇒ ObjectSummary
- #wait_until_not_exists(options = {}, &block) ⇒ ObjectSummary
Constructor Details
#initialize(bucket_name, key, options = {}) ⇒ ObjectSummary #initialize(options = {}) ⇒ ObjectSummary
Returns a new instance of ObjectSummary.
22 23 24 25 26 27 28 29 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 22 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @bucket_name = extract_bucket_name(args, ) @key = extract_key(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() @waiter_block_warned = false end |
Instance Method Details
#acl ⇒ ObjectAcl
1010 1011 1012 1013 1014 1015 1016 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 1010 def acl ObjectAcl.new( bucket_name: @bucket_name, object_key: @key, client: @client ) end |
#bucket ⇒ Bucket
1019 1020 1021 1022 1023 1024 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 1019 def bucket Bucket.new( name: @bucket_name, client: @client ) end |
#bucket_name ⇒ String
34 35 36 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 34 def bucket_name @bucket_name end |
#copy_from(source, options = {}) ⇒ Types::CopyObjectOutput
413 414 415 416 417 418 419 420 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 413 def copy_from( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.copy_object() resp.data end |
#copy_to(target, options = {}) ⇒ Object
19 20 21 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 19 def copy_to(target, = {}) object.copy_to(target, ) end |
#data ⇒ Types::Object
Returns the data for this Aws::S3::ObjectSummary.
92 93 94 95 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 92 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
100 101 102 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 100 def data_loaded? !!@data end |
#delete(options = {}) ⇒ Types::DeleteObjectOutput
452 453 454 455 456 457 458 459 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 452 def delete( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.delete_object() resp.data end |
#download_file(destination, options = {}) ⇒ Boolean
Returns ‘true` when the file is downloaded without any errors.
74 75 76 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 74 def download_file(destination, = {}) object.download_file(destination, ) end |
#etag ⇒ String
The entity tag is an MD5 hash of the object. ETag reflects only changes to the contents of an object, not its metadata.
52 53 54 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 52 def etag data[:etag] end |
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the ObjectSummary exists.
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 107 def exists?( = {}) begin wait_until_exists(.merge(max_attempts: 1)) true rescue Aws::Waiters::Errors::UnexpectedError => e raise e.error rescue Aws::Waiters::Errors::WaiterFailed false end end |
#get(options = {}, &block) ⇒ Types::GetObjectOutput
542 543 544 545 546 547 548 549 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 542 def get( = {}, &block) = .merge( bucket: @bucket_name, key: @key ) resp = @client.get_object(, &block) resp.data end |
#identifiers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1059 1060 1061 1062 1063 1064 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 1059 def identifiers { bucket_name: @bucket_name, key: @key } end |
#initiate_multipart_upload(options = {}) ⇒ MultipartUpload
669 670 671 672 673 674 675 676 677 678 679 680 681 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 669 def initiate_multipart_upload( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.create_multipart_upload() MultipartUpload.new( bucket_name: @bucket_name, object_key: @key, id: resp.data.upload_id, client: @client ) end |
#key ⇒ String
39 40 41 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 39 def key @key end |
#last_modified ⇒ Time
The date the Object was Last Modified
45 46 47 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 45 def last_modified data[:last_modified] end |
#load ⇒ Object Also known as: reload
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
83 84 85 86 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 83 def load msg = "#load is not implemented, data only available via enumeration" raise NotImplementedError, msg end |
#move_to(target, options = {}) ⇒ void
This method returns an undefined value.
27 28 29 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 27 def move_to(target, = {}) object.move_to(target, ) end |
#multipart_upload(id) ⇒ MultipartUpload
1028 1029 1030 1031 1032 1033 1034 1035 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 1028 def multipart_upload(id) MultipartUpload.new( bucket_name: @bucket_name, object_key: @key, id: id, client: @client ) end |
#object ⇒ Object
1038 1039 1040 1041 1042 1043 1044 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 1038 def object Object.new( bucket_name: @bucket_name, key: @key, client: @client ) end |
#owner ⇒ Types::Owner
The owner of the object
70 71 72 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 70 def owner data[:owner] end |
#presigned_post(options = {}) ⇒ PresignedPost
35 36 37 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 35 def presigned_post( = {}) object.presigned_post() end |
#presigned_url(http_method, params = {}) ⇒ String
43 44 45 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 43 def presigned_url(http_method, params = {}) object.presigned_url(http_method, params) end |
#public_url(options = {}) ⇒ String
51 52 53 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 51 def public_url( = {}) object.public_url() end |
#put(options = {}) ⇒ Types::PutObjectOutput
886 887 888 889 890 891 892 893 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 886 def put( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.put_object() resp.data end |
#restore_object(options = {}) ⇒ Types::RestoreObjectOutput
998 999 1000 1001 1002 1003 1004 1005 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 998 def restore_object( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.restore_object() resp.data end |
#size ⇒ Integer Also known as: content_length
Size in bytes of the object
58 59 60 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 58 def size data[:size] end |
#storage_class ⇒ String
The class of storage used to store the object.
64 65 66 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 64 def storage_class data[:storage_class] end |
#upload_file(source, options = {}) ⇒ Boolean
Returns ‘true` when the object is uploaded without any errors.
59 60 61 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 59 def upload_file(source, = {}) object.upload_file(source, ) end |
#upload_stream(options = {}, &block) ⇒ Boolean
Returns ‘true` when the object is uploaded without any errors.
66 67 68 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 66 def upload_stream( = {}, &block) object.upload_stream(, &block) end |
#version(id) ⇒ ObjectVersion
1048 1049 1050 1051 1052 1053 1054 1055 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 1048 def version(id) ObjectVersion.new( bucket_name: @bucket_name, object_key: @key, id: id, client: @client ) end |
#wait_until(options = {}) {|resource| ... } ⇒ Resource
Use [Aws::S3::Client] #wait_until instead
The waiting operation is performed on a copy. The original resource remains unchanged.
Waiter polls an API operation until a resource enters a desired state.
## Basic Usage
Waiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.
# polls in a loop until condition is true
resource.wait_until() {|resource| condition}
## Example
instance.wait_until(max_attempts:10, delay:5) do |instance|
instance.state.name == 'running'
end
## Configuration
You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. The waiting condition is set by passing a block to #wait_until:
# poll for ~25 seconds
resource.wait_until(max_attempts:5,delay:5) {|resource|...}
## Callbacks
You can be notified before each polling attempt and before each delay. If you throw ‘:success` or `:failure` from these callbacks, it will terminate the waiter.
started_at = Time.now
# poll for 1 hour, instead of a number of attempts
proc = Proc.new do |attempts, response|
throw :failure if Time.now - started_at > 3600
end
# disable max attempts
instance.wait_until(before_wait:proc, max_attempts:nil) {...}
## Handling Errors
When a waiter is successful, it returns the Resource. When a waiter fails, it raises an error.
begin
resource.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
# resource did not enter the desired state in time
end
attempts attempt in seconds invoked before each attempt invoked before each wait
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 236 def wait_until( = {}, &block) self_copy = self.dup attempts = 0 [:max_attempts] = 10 unless .key?(:max_attempts) [:delay] ||= 10 [:poller] = Proc.new do attempts += 1 if block.call(self_copy) [:success, self_copy] else self_copy.reload unless attempts == [:max_attempts] :retry end end Aws::Waiters::Waiter.new().wait({}) end |
#wait_until_exists(options = {}, &block) ⇒ ObjectSummary
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 124 def wait_until_exists( = {}, &block) , params = () waiter = Waiters::ObjectExists.new() yield_waiter_and_warn(waiter, &block) if block_given? waiter.wait(params.merge(bucket: @bucket_name, key: @key)) ObjectSummary.new({ bucket_name: @bucket_name, key: @key, client: @client }) end |
#wait_until_not_exists(options = {}, &block) ⇒ ObjectSummary
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 143 def wait_until_not_exists( = {}, &block) , params = () waiter = Waiters::ObjectNotExists.new() yield_waiter_and_warn(waiter, &block) if block_given? waiter.wait(params.merge(bucket: @bucket_name, key: @key)) ObjectSummary.new({ bucket_name: @bucket_name, key: @key, client: @client }) end |