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
-
#checksum_algorithm ⇒ Array<String>
The algorithm that was used to create a checksum of the object.
-
#checksum_type ⇒ String
The checksum type that is used to calculate the object’s checksum value.
-
#etag ⇒ String
The entity tag is a hash of the object.
- #key ⇒ String
-
#last_modified ⇒ Time
Creation date of the object.
-
#owner ⇒ Types::Owner
The owner of the object.
-
#restore_status ⇒ Types::RestoreStatus
Specifies the restoration status of an 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.
24 25 26 27 28 29 30 31 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 24 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
2787 2788 2789 2790 2791 2792 2793 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 2787 def acl ObjectAcl.new( bucket_name: @bucket_name, object_key: @key, client: @client ) end |
#bucket ⇒ Bucket
2796 2797 2798 2799 2800 2801 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 2796 def bucket Bucket.new( name: @bucket_name, client: @client ) end |
#bucket_name ⇒ String
36 37 38 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 36 def bucket_name @bucket_name end |
#checksum_algorithm ⇒ Array<String>
The algorithm that was used to create a checksum of the object.
83 84 85 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 83 def checksum_algorithm data[:checksum_algorithm] end |
#checksum_type ⇒ String
The checksum type that is used to calculate the object’s checksum value. For more information, see [Checking object integrity] in the *Amazon S3 User Guide*.
[1]: docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html
95 96 97 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 95 def checksum_type data[:checksum_type] end |
#client ⇒ Client
150 151 152 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 150 def client @client end |
#copy_from(source, options = {}) ⇒ Types::CopyObjectOutput
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 1056 def copy_from( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.copy_object() end resp.data end |
#copy_to(target, options = {}) ⇒ Object
24 25 26 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 24 def copy_to(target, = {}) object.copy_to(target, ) end |
#data ⇒ Types::Object
Returns the data for this Aws::S3::ObjectSummary.
165 166 167 168 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 165 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
173 174 175 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 173 def data_loaded? !!@data end |
#delete(options = {}) ⇒ Types::DeleteObjectOutput
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 1165 def delete( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.delete_object() end resp.data end |
#download_file(destination, options = {}) ⇒ Boolean
Returns ‘true` when the file is downloaded without any errors.
79 80 81 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 79 def download_file(destination, = {}) object.download_file(destination, ) end |
#etag ⇒ String
The entity tag is a hash of the object. The ETag reflects changes only to the contents of an object, not its metadata. The ETag may or may not be an MD5 digest of the object data. Whether or not it is depends on how the object was created and how it is encrypted as described below:
-
Objects created by the PUT Object, POST Object, or Copy operation, or through the Amazon Web Services Management Console, and are encrypted by SSE-S3 or plaintext, have ETags that are an MD5 digest of their object data.
-
Objects created by the PUT Object, POST Object, or Copy operation, or through the Amazon Web Services Management Console, and are encrypted by SSE-C or SSE-KMS, have ETags that are not an MD5 digest of their object data.
-
If an object is created by either the Multipart Upload or Part Copy operation, the ETag is not an MD5 digest, regardless of the method of encryption. If an object is larger than 16 MB, the Amazon Web Services Management Console will upload or copy that object as a Multipart Upload, and therefore the ETag will not be an MD5 digest.
<note markdown=“1”> **Directory buckets** - MD5 is not supported by directory buckets.
</note>
77 78 79 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 77 def etag data[:etag] end |
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the ObjectSummary exists.
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 180 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
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 1430 def get( = {}, &block) = .merge( bucket: @bucket_name, key: @key ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.get_object(, &block) end 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.
2836 2837 2838 2839 2840 2841 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 2836 def identifiers { bucket_name: @bucket_name, key: @key } end |
#initiate_multipart_upload(options = {}) ⇒ MultipartUpload
2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 2008 def initiate_multipart_upload( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.create_multipart_upload() end MultipartUpload.new( bucket_name: @bucket_name, object_key: @key, id: resp.data.upload_id, client: @client ) end |
#key ⇒ String
41 42 43 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 41 def key @key end |
#last_modified ⇒ Time
Creation date of the object.
47 48 49 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 47 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.
156 157 158 159 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 156 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.
32 33 34 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 32 def move_to(target, = {}) object.move_to(target, ) end |
#multipart_upload(id) ⇒ MultipartUpload
2805 2806 2807 2808 2809 2810 2811 2812 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 2805 def multipart_upload(id) MultipartUpload.new( bucket_name: @bucket_name, object_key: @key, id: id, client: @client ) end |
#object ⇒ Object
2815 2816 2817 2818 2819 2820 2821 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 2815 def object Object.new( bucket_name: @bucket_name, key: @key, client: @client ) end |
#owner ⇒ Types::Owner
The owner of the object
<note markdown=“1”> **Directory buckets** - The bucket owner is returned as the object owner.
</note>
123 124 125 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 123 def owner data[:owner] end |
#presigned_post(options = {}) ⇒ PresignedPost
40 41 42 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 40 def presigned_post( = {}) object.presigned_post() end |
#presigned_url(http_method, params = {}) ⇒ String
48 49 50 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 48 def presigned_url(http_method, params = {}) object.presigned_url(http_method, params) end |
#public_url(options = {}) ⇒ String
56 57 58 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 56 def public_url( = {}) object.public_url() end |
#put(options = {}) ⇒ Types::PutObjectOutput
2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 2632 def put( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.put_object() end resp.data end |
#restore_object(options = {}) ⇒ Types::RestoreObjectOutput
2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 2773 def restore_object( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.restore_object() end resp.data end |
#restore_status ⇒ Types::RestoreStatus
Specifies the restoration status of an object. Objects in certain storage classes must be restored before they can be retrieved. For more information about these storage classes and how to work with archived objects, see [ Working with archived objects] in the *Amazon S3 User Guide*.
<note markdown=“1”> This functionality is not supported for directory buckets. Only the S3 Express One Zone storage class is supported by directory buckets to store objects.
</note>
[1]: docs.aws.amazon.com/AmazonS3/latest/userguide/archived-objects.html
143 144 145 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 143 def restore_status data[:restore_status] end |
#size ⇒ Integer Also known as: content_length
Size in bytes of the object
101 102 103 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 101 def size data[:size] end |
#storage_class ⇒ String
The class of storage used to store the object.
<note markdown=“1”> **Directory buckets** - Only the S3 Express One Zone storage class is supported by directory buckets to store objects.
</note>
112 113 114 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 112 def storage_class data[:storage_class] end |
#upload_file(source, options = {}) ⇒ Boolean
Returns ‘true` when the object is uploaded without any errors.
64 65 66 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 64 def upload_file(source, = {}) object.upload_file(source, ) end |
#upload_stream(options = {}, &block) ⇒ Boolean
Returns ‘true` when the object is uploaded without any errors.
71 72 73 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 71 def upload_stream( = {}, &block) object.upload_stream(, &block) end |
#version(id) ⇒ ObjectVersion
2825 2826 2827 2828 2829 2830 2831 2832 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 2825 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
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 313 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::Plugins::UserAgent.metric('RESOURCE_MODEL') do Aws::Waiters::Waiter.new().wait({}) end end |
#wait_until_exists(options = {}, &block) ⇒ ObjectSummary
197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 197 def wait_until_exists( = {}, &block) , params = () waiter = Waiters::ObjectExists.new() yield_waiter_and_warn(waiter, &block) if block_given? Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do waiter.wait(params.merge(bucket: @bucket_name, key: @key)) end ObjectSummary.new({ bucket_name: @bucket_name, key: @key, client: @client }) end |
#wait_until_not_exists(options = {}, &block) ⇒ ObjectSummary
218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 218 def wait_until_not_exists( = {}, &block) , params = () waiter = Waiters::ObjectNotExists.new() yield_waiter_and_warn(waiter, &block) if block_given? Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do waiter.wait(params.merge(bucket: @bucket_name, key: @key)) end ObjectSummary.new({ bucket_name: @bucket_name, key: @key, client: @client }) end |