aws-sdk-s3 1.193.0 → 1.198.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,246 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module S3
5
+ # A high-level S3 transfer utility that provides enhanced upload and download
6
+ # capabilities with automatic multipart handling, progress tracking, and
7
+ # handling of large files. The following features are supported:
8
+ #
9
+ # * upload a file with multipart upload
10
+ # * upload a stream with multipart upload
11
+ # * download a S3 object with multipart download
12
+ # * track transfer progress by using progress listener
13
+ #
14
+ class TransferManager
15
+ # @param [Hash] options
16
+ # @option options [S3::Client] :client (S3::Client.new)
17
+ # The S3 client to use for {TransferManager} operations. If not provided, a new default client
18
+ # will be created automatically.
19
+ def initialize(options = {})
20
+ @client = options.delete(:client) || Client.new
21
+ end
22
+
23
+ # @return [S3::Client]
24
+ attr_reader :client
25
+
26
+ # Downloads a file in S3 to a path on disk.
27
+ #
28
+ # # small files (< 5MB) are downloaded in a single API call
29
+ # tm = TransferManager.new
30
+ # tm.download_file('/path/to/file', bucket: 'bucket', key: 'key')
31
+ #
32
+ # Files larger than 5MB are downloaded using multipart method:
33
+ #
34
+ # # large files are split into parts and the parts are downloaded in parallel
35
+ # tm.download_file('/path/to/large_file', bucket: 'bucket', key: 'key')
36
+ #
37
+ # You can provide a callback to monitor progress of the download:
38
+ #
39
+ # # bytes and part_sizes are each an array with 1 entry per part
40
+ # # part_sizes may not be known until the first bytes are retrieved
41
+ # progress = proc do |bytes, part_sizes, file_size|
42
+ # bytes.map.with_index do |b, i|
43
+ # puts "Part #{i + 1}: #{b} / #{part_sizes[i]}".join(' ') + "Total: #{100.0 * bytes.sum / file_size}%"
44
+ # end
45
+ # end
46
+ # tm.download_file('/path/to/file', bucket: 'bucket', key: 'key', progress_callback: progress)
47
+ #
48
+ # @param [String, Pathname, File, Tempfile] destination
49
+ # Where to download the file to. This can either be a String or Pathname to the file, an open File object,
50
+ # or an open Tempfile object. If you pass an open File or Tempfile object, then you are responsible for
51
+ # closing it after the download completes.
52
+ #
53
+ # @param [String] bucket
54
+ # The name of the S3 bucket to upload to.
55
+ #
56
+ # @param [String] key
57
+ # The object key name in S3 bucket.
58
+ #
59
+ # @param [Hash] options
60
+ # Additional options for {Client#get_object} and #{Client#head_object} may be provided.
61
+ #
62
+ # @option options [String] :mode ("auto") `"auto"`, `"single_request"` or `"get_range"`
63
+ #
64
+ # * `"auto"` mode is enabled by default, which performs `multipart_download`
65
+ # * `"single_request`" mode forces only 1 GET request is made in download
66
+ # * `"get_range"` mode requires `:chunk_size` parameter to configured in customizing each range size
67
+ #
68
+ # @option options [Integer] :chunk_size required in `"get_range"` mode.
69
+ #
70
+ # @option options [Integer] :thread_count (10) Customize threads used in the multipart download.
71
+ #
72
+ # @option options [String] :version_id The object version id used to retrieve the object.
73
+ #
74
+ # @see https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectVersioning.html ObjectVersioning
75
+ #
76
+ # @option options [String] :checksum_mode ("ENABLED")
77
+ # When `"ENABLED"` and the object has a stored checksum, it will be used to validate the download and will
78
+ # raise an `Aws::Errors::ChecksumError` if checksum validation fails. You may provide a `on_checksum_validated`
79
+ # callback if you need to verify that validation occurred and which algorithm was used.
80
+ # To disable checksum validation, set `checksum_mode` to `"DISABLED"`.
81
+ #
82
+ # @option options [Callable] :on_checksum_validated
83
+ # Called each time a request's checksum is validated with the checksum algorithm and the
84
+ # response. For multipart downloads, this will be called for each part that is downloaded and validated.
85
+ #
86
+ # @option options [Proc] :progress_callback
87
+ # A Proc that will be called when each chunk of the download is received. It will be invoked with
88
+ # `bytes_read`, `part_sizes`, `file_size`. When the object is downloaded as parts (rather than by ranges),
89
+ # the `part_sizes` will not be known ahead of time and will be `nil` in the callback until the first bytes
90
+ # in the part are received.
91
+ #
92
+ # @raise [MultipartDownloadError] Raised when an object validation fails outside of service errors.
93
+ #
94
+ # @return [Boolean] Returns `true` when the file is downloaded without any errors.
95
+ #
96
+ # @see Client#get_object
97
+ # @see Client#head_object
98
+ def download_file(destination, bucket:, key:, **options)
99
+ downloader = FileDownloader.new(client: @client)
100
+ downloader.download(destination, options.merge(bucket: bucket, key: key))
101
+ true
102
+ end
103
+
104
+ # Uploads a file from disk to S3.
105
+ #
106
+ # # a small file are uploaded with PutObject API
107
+ # tm = TransferManager.new
108
+ # tm.upload_file('/path/to/small_file', bucket: 'bucket', key: 'key')
109
+ #
110
+ # Files larger than or equal to `:multipart_threshold` are uploaded using multipart upload APIs.
111
+ #
112
+ # # large files are automatically split into parts and the parts are uploaded in parallel
113
+ # tm.upload_file('/path/to/large_file', bucket: 'bucket', key: 'key')
114
+ #
115
+ # The response of the S3 upload API is yielded if a block given.
116
+ #
117
+ # # API response will have etag value of the file
118
+ # tm.upload_file('/path/to/file', bucket: 'bucket', key: 'key') do |response|
119
+ # etag = response.etag
120
+ # end
121
+ #
122
+ # You can provide a callback to monitor progress of the upload:
123
+ #
124
+ # # bytes and totals are each an array with 1 entry per part
125
+ # progress = proc do |bytes, totals|
126
+ # bytes.map.with_index do |b, i|
127
+ # puts "Part #{i + 1}: #{b} / #{totals[i]} " + "Total: #{100.0 * bytes.sum / totals.sum}%"
128
+ # end
129
+ # end
130
+ # tm.upload_file('/path/to/file', bucket: 'bucket', key: 'key', progress_callback: progress)
131
+ #
132
+ # @param [String, Pathname, File, Tempfile] source
133
+ # A file on the local file system that will be uploaded. This can either be a `String` or `Pathname` to the
134
+ # file, an open `File` object, or an open `Tempfile` object. If you pass an open `File` or `Tempfile` object,
135
+ # then you are responsible for closing it after the upload completes. When using an open Tempfile, rewind it
136
+ # before uploading or else the object will be empty.
137
+ #
138
+ # @param [String] bucket
139
+ # The name of the S3 bucket to upload to.
140
+ #
141
+ # @param [String] key
142
+ # The object key name for the uploaded file.
143
+ #
144
+ # @param [Hash] options
145
+ # Additional options for {Client#put_object} when file sizes below the multipart threshold.
146
+ # For files larger than the multipart threshold, options for {Client#create_multipart_upload},
147
+ # {Client#complete_multipart_upload}, and {Client#upload_part} can be provided.
148
+ #
149
+ # @option options [Integer] :multipart_threshold (104857600)
150
+ # Files larger han or equal to `:multipart_threshold` are uploaded using the S3 multipart upload APIs.
151
+ # Default threshold is `100MB`.
152
+ #
153
+ # @option options [Integer] :thread_count (10)
154
+ # The number of parallel multipart uploads. This option is not used if the file is smaller than
155
+ # `:multipart_threshold`.
156
+ #
157
+ # @option options [Proc] :progress_callback (nil)
158
+ # A Proc that will be called when each chunk of the upload is sent.
159
+ # It will be invoked with `[bytes_read]` and `[total_sizes]`.
160
+ #
161
+ # @raise [MultipartUploadError] If an file is being uploaded in parts, and the upload can not be completed,
162
+ # then the upload is aborted and this error is raised. The raised error has a `#errors` method that
163
+ # returns the failures that caused the upload to be aborted.
164
+ #
165
+ # @return [Boolean] Returns `true` when the file is uploaded without any errors.
166
+ #
167
+ # @see Client#put_object
168
+ # @see Client#create_multipart_upload
169
+ # @see Client#complete_multipart_upload
170
+ # @see Client#upload_part
171
+ def upload_file(source, bucket:, key:, **options)
172
+ uploading_options = options.dup
173
+ uploader = FileUploader.new(
174
+ multipart_threshold: uploading_options.delete(:multipart_threshold),
175
+ client: @client
176
+ )
177
+ response = uploader.upload(source, uploading_options.merge(bucket: bucket, key: key))
178
+ yield response if block_given?
179
+ true
180
+ end
181
+
182
+ # Uploads a stream in a streaming fashion to S3.
183
+ #
184
+ # Passed chunks automatically split into multipart upload parts and the parts are uploaded in parallel.
185
+ # This allows for streaming uploads that never touch the disk.
186
+ #
187
+ # **Note**: There are known issues in JRuby until jruby-9.1.15.0, so avoid using this with older JRuby versions.
188
+ #
189
+ # @example Streaming chunks of data
190
+ # tm = TransferManager.new
191
+ # tm.upload_stream(bucket: 'bucket', key: 'key') do |write_stream|
192
+ # 10.times { write_stream << 'foo' }
193
+ # end
194
+ # @example Streaming chunks of data
195
+ # tm.upload_stream(bucket: 'bucket', key: 'key') do |write_stream|
196
+ # IO.copy_stream(IO.popen('ls'), write_stream)
197
+ # end
198
+ # @example Streaming chunks of data
199
+ # tm.upload_stream(bucket: 'bucket', key: 'key') do |write_stream|
200
+ # IO.copy_stream(STDIN, write_stream)
201
+ # end
202
+ #
203
+ # @param [String] bucket
204
+ # The name of the S3 bucket to upload to.
205
+ #
206
+ # @param [String] key
207
+ # The object key name for the uploaded file.
208
+ #
209
+ # @param [Hash] options
210
+ # Additional options for {Client#create_multipart_upload}, {Client#complete_multipart_upload}, and
211
+ # {Client#upload_part} can be provided.
212
+ #
213
+ # @option options [Integer] :thread_count (10)
214
+ # The number of parallel multipart uploads.
215
+ #
216
+ # @option options [Boolean] :tempfile (false)
217
+ # Normally read data is stored in memory when building the parts in order to complete the underlying
218
+ # multipart upload. By passing `:tempfile => true`, the data read will be temporarily stored on disk reducing
219
+ # the memory footprint vastly.
220
+ #
221
+ # @option options [Integer] :part_size (5242880)
222
+ # Define how big each part size but the last should be. Default `:part_size` is `5 * 1024 * 1024`.
223
+ #
224
+ # @raise [MultipartUploadError] If an object is being uploaded in parts, and the upload can not be completed,
225
+ # then the upload is aborted and this error is raised. The raised error has a `#errors` method that returns
226
+ # the failures that caused the upload to be aborted.
227
+ #
228
+ # @return [Boolean] Returns `true` when the object is uploaded without any errors.
229
+ #
230
+ # @see Client#create_multipart_upload
231
+ # @see Client#complete_multipart_upload
232
+ # @see Client#upload_part
233
+ def upload_stream(bucket:, key:, **options, &block)
234
+ uploading_options = options.dup
235
+ uploader = MultipartStreamUploader.new(
236
+ client: @client,
237
+ thread_count: uploading_options.delete(:thread_count),
238
+ tempfile: uploading_options.delete(:tempfile),
239
+ part_size: uploading_options.delete(:part_size)
240
+ )
241
+ uploader.upload(uploading_options.merge(bucket: bucket, key: key), &block)
242
+ true
243
+ end
244
+ end
245
+ end
246
+ end
data/lib/aws-sdk-s3.rb CHANGED
@@ -75,7 +75,7 @@ module Aws::S3
75
75
  autoload :ObjectVersion, 'aws-sdk-s3/object_version'
76
76
  autoload :EventStreams, 'aws-sdk-s3/event_streams'
77
77
 
78
- GEM_VERSION = '1.193.0'
78
+ GEM_VERSION = '1.198.0'
79
79
 
80
80
  end
81
81
 
data/sig/client.rbs CHANGED
@@ -20,6 +20,7 @@ module Aws
20
20
  ?account_id: String,
21
21
  ?active_endpoint_cache: bool,
22
22
  ?adaptive_retry_wait_to_fill: bool,
23
+ ?auth_scheme_preference: Array[String],
23
24
  ?client_side_monitoring: bool,
24
25
  ?client_side_monitoring_client_id: String,
25
26
  ?client_side_monitoring_host: String,
data/sig/resource.rbs CHANGED
@@ -20,6 +20,7 @@ module Aws
20
20
  ?account_id: String,
21
21
  ?active_endpoint_cache: bool,
22
22
  ?adaptive_retry_wait_to_fill: bool,
23
+ ?auth_scheme_preference: Array[String],
23
24
  ?client_side_monitoring: bool,
24
25
  ?client_side_monitoring_client_id: String,
25
26
  ?client_side_monitoring_host: String,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-sdk-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.193.0
4
+ version: 1.198.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amazon Web Services
@@ -46,7 +46,7 @@ dependencies:
46
46
  version: '3'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 3.225.0
49
+ version: 3.231.0
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
@@ -56,7 +56,7 @@ dependencies:
56
56
  version: '3'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 3.225.0
59
+ version: 3.231.0
60
60
  description: Official AWS Ruby gem for Amazon Simple Storage Service (Amazon S3).
61
61
  This gem is part of the AWS SDK for Ruby.
62
62
  email:
@@ -134,6 +134,7 @@ files:
134
134
  - lib/aws-sdk-s3/file_part.rb
135
135
  - lib/aws-sdk-s3/file_uploader.rb
136
136
  - lib/aws-sdk-s3/legacy_signer.rb
137
+ - lib/aws-sdk-s3/multipart_download_error.rb
137
138
  - lib/aws-sdk-s3/multipart_file_uploader.rb
138
139
  - lib/aws-sdk-s3/multipart_stream_uploader.rb
139
140
  - lib/aws-sdk-s3/multipart_upload.rb
@@ -169,6 +170,7 @@ files:
169
170
  - lib/aws-sdk-s3/presigned_post.rb
170
171
  - lib/aws-sdk-s3/presigner.rb
171
172
  - lib/aws-sdk-s3/resource.rb
173
+ - lib/aws-sdk-s3/transfer_manager.rb
172
174
  - lib/aws-sdk-s3/types.rb
173
175
  - lib/aws-sdk-s3/waiters.rb
174
176
  - sig/bucket.rbs