aws-sdk-s3 1.81.1 → 1.114.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +903 -0
  3. data/LICENSE.txt +202 -0
  4. data/VERSION +1 -0
  5. data/lib/aws-sdk-s3/arn/access_point_arn.rb +69 -0
  6. data/lib/aws-sdk-s3/arn/multi_region_access_point_arn.rb +68 -0
  7. data/lib/aws-sdk-s3/arn/object_lambda_arn.rb +69 -0
  8. data/lib/aws-sdk-s3/arn/outpost_access_point_arn.rb +74 -0
  9. data/lib/aws-sdk-s3/bucket.rb +172 -46
  10. data/lib/aws-sdk-s3/bucket_acl.rb +28 -6
  11. data/lib/aws-sdk-s3/bucket_cors.rb +29 -9
  12. data/lib/aws-sdk-s3/bucket_lifecycle.rb +30 -9
  13. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +31 -9
  14. data/lib/aws-sdk-s3/bucket_logging.rb +25 -6
  15. data/lib/aws-sdk-s3/bucket_notification.rb +21 -9
  16. data/lib/aws-sdk-s3/bucket_policy.rb +27 -7
  17. data/lib/aws-sdk-s3/bucket_request_payment.rb +27 -8
  18. data/lib/aws-sdk-s3/bucket_tagging.rb +27 -7
  19. data/lib/aws-sdk-s3/bucket_versioning.rb +70 -10
  20. data/lib/aws-sdk-s3/bucket_website.rb +27 -7
  21. data/lib/aws-sdk-s3/client.rb +4415 -1650
  22. data/lib/aws-sdk-s3/client_api.rb +661 -41
  23. data/lib/aws-sdk-s3/customizations/bucket.rb +15 -7
  24. data/lib/aws-sdk-s3/customizations/object.rb +120 -21
  25. data/lib/aws-sdk-s3/customizations.rb +1 -1
  26. data/lib/aws-sdk-s3/encryption/client.rb +1 -1
  27. data/lib/aws-sdk-s3/encryption/decrypt_handler.rb +0 -4
  28. data/lib/aws-sdk-s3/encryptionV2/client.rb +1 -1
  29. data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +0 -4
  30. data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +3 -3
  31. data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +0 -4
  32. data/lib/aws-sdk-s3/errors.rb +22 -1
  33. data/lib/aws-sdk-s3/event_streams.rb +1 -1
  34. data/lib/aws-sdk-s3/file_downloader.rb +7 -2
  35. data/lib/aws-sdk-s3/file_uploader.rb +9 -4
  36. data/lib/aws-sdk-s3/legacy_signer.rb +15 -25
  37. data/lib/aws-sdk-s3/multipart_file_uploader.rb +26 -7
  38. data/lib/aws-sdk-s3/multipart_upload.rb +133 -19
  39. data/lib/aws-sdk-s3/multipart_upload_part.rb +152 -23
  40. data/lib/aws-sdk-s3/object.rb +501 -126
  41. data/lib/aws-sdk-s3/object_acl.rb +39 -9
  42. data/lib/aws-sdk-s3/object_summary.rb +330 -110
  43. data/lib/aws-sdk-s3/object_version.rb +80 -49
  44. data/lib/aws-sdk-s3/plugins/accelerate.rb +13 -4
  45. data/lib/aws-sdk-s3/plugins/arn.rb +254 -0
  46. data/lib/aws-sdk-s3/plugins/bucket_dns.rb +1 -3
  47. data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +1 -1
  48. data/lib/aws-sdk-s3/plugins/dualstack.rb +33 -32
  49. data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +2 -1
  50. data/lib/aws-sdk-s3/plugins/get_bucket_location_fix.rb +1 -1
  51. data/lib/aws-sdk-s3/plugins/iad_regional_endpoint.rb +18 -7
  52. data/lib/aws-sdk-s3/plugins/md5s.rb +5 -3
  53. data/lib/aws-sdk-s3/plugins/object_lambda_endpoint.rb +25 -0
  54. data/lib/aws-sdk-s3/plugins/s3_signer.rb +66 -17
  55. data/lib/aws-sdk-s3/plugins/skip_whole_multipart_get_checksums.rb +31 -0
  56. data/lib/aws-sdk-s3/plugins/streaming_retry.rb +23 -2
  57. data/lib/aws-sdk-s3/presigned_post.rb +38 -19
  58. data/lib/aws-sdk-s3/presigner.rb +33 -17
  59. data/lib/aws-sdk-s3/resource.rb +23 -3
  60. data/lib/aws-sdk-s3/types.rb +4792 -1089
  61. data/lib/aws-sdk-s3/waiters.rb +1 -1
  62. data/lib/aws-sdk-s3.rb +2 -2
  63. metadata +21 -13
  64. data/lib/aws-sdk-s3/plugins/bucket_arn.rb +0 -212
@@ -12,13 +12,12 @@ module Aws
12
12
  # Define a new initialize method that extracts out a bucket ARN.
13
13
  define_method(:initialize) do |*args|
14
14
  old_initialize.bind(self).call(*args)
15
- bucket_name, region, arn = Plugins::BucketARN.resolve_arn!(
15
+ resolved_region, arn = Plugins::ARN.resolve_arn!(
16
16
  name,
17
17
  client.config.region,
18
18
  client.config.s3_use_arn_region
19
19
  )
20
- @name = bucket_name
21
- @client.config.region = region
20
+ @resolved_region = resolved_region
22
21
  @arn = arn
23
22
  end
24
23
 
@@ -89,20 +88,29 @@ module Aws
89
88
  # You can pass `virtual_host: true` to use the bucket name as the
90
89
  # host name.
91
90
  #
92
- # bucket = s3.bucket('my.bucket.com')
91
+ # bucket = s3.bucket('my-bucket.com')
93
92
  # bucket.url(virtual_host: true)
94
- # #=> "http://my.bucket.com"
93
+ # #=> "http://my-bucket.com"
95
94
  #
96
95
  # @option options [Boolean] :virtual_host (false) When `true`,
97
96
  # the bucket name will be used as the host name. This is useful
98
97
  # when you have a CNAME configured for this bucket.
99
98
  #
99
+ # @option options [Boolean] :secure (true) When `false`, http
100
+ # will be used with virtual_host. This is required when
101
+ # the bucket name has a dot (.) in it.
102
+ #
100
103
  # @return [String] the URL for this bucket.
101
104
  def url(options = {})
102
105
  if options[:virtual_host]
103
- "http://#{name}"
106
+ scheme = options.fetch(:secure, true) ? 'https' : 'http'
107
+ "#{scheme}://#{name}"
104
108
  elsif @arn
105
- Plugins::BucketARN.resolve_url!(URI.parse(s3_bucket_url), @arn).to_s
109
+ Plugins::ARN.resolve_url!(
110
+ client.config.endpoint.dup,
111
+ @arn,
112
+ @resolved_region
113
+ ).to_s
106
114
  else
107
115
  s3_bucket_url
108
116
  end
@@ -153,21 +153,35 @@ module Aws
153
153
  # obj.presigned_url(:put, acl: 'public-read')
154
154
  # #=> "https://bucket-name.s3.amazonaws.com/object-key?..."
155
155
  #
156
- # @param [Symbol] http_method
157
- # The HTTP method to generate a presigned URL for. Valid values
158
- # are `:get`, `:put`, `:head`, and `:delete`.
156
+ # @example Pre-signed UploadPart PUT
157
+ #
158
+ # # the object uploaded using this URL will be publicly accessible
159
+ # obj.presigned_url(:upload_part, part_number: 1, upload_id: 'uploadIdToken')
160
+ # #=> "https://bucket-name.s3.amazonaws.com/object-key?..."
161
+ #
162
+ # @param [Symbol] method
163
+ # The S3 operation to generate a presigned URL for. Valid values
164
+ # are `:get`, `:put`, `:head`, `:delete`, `:create_multipart_upload`,
165
+ # `:list_multipart_uploads`, `:complete_multipart_upload`,
166
+ # `:abort_multipart_upload`, `:list_parts`, and `:upload_part`.
159
167
  #
160
168
  # @param [Hash] params
161
169
  # Additional request parameters to use when generating the pre-signed
162
170
  # URL. See the related documentation in {Client} for accepted
163
171
  # params.
164
172
  #
165
- # | HTTP Method | Client Method |
166
- # |---------------|------------------------|
167
- # | `:get` | {Client#get_object} |
168
- # | `:put` | {Client#put_object} |
169
- # | `:head` | {Client#head_object} |
170
- # | `:delete` | {Client#delete_object} |
173
+ # | Method | Client Method |
174
+ # |------------------------------|------------------------------------|
175
+ # | `:get` | {Client#get_object} |
176
+ # | `:put` | {Client#put_object} |
177
+ # | `:head` | {Client#head_object} |
178
+ # | `:delete` | {Client#delete_object} |
179
+ # | `:create_multipart_upload` | {Client#create_multipart_upload} |
180
+ # | `:list_multipart_uploads` | {Client#list_multipart_uploads} |
181
+ # | `:complete_multipart_upload` | {Client#complete_multipart_upload} |
182
+ # | `:abort_multipart_upload` | {Client#abort_multipart_upload} |
183
+ # | `:list_parts` | {Client#list_parts} |
184
+ # | `:upload_part` | {Client#upload_part} |
171
185
  #
172
186
  # @option params [Boolean] :virtual_host (false) When `true` the
173
187
  # presigned URL will use the bucket name as a virtual host.
@@ -188,10 +202,88 @@ module Aws
188
202
  #
189
203
  # @return [String]
190
204
  #
191
- def presigned_url(http_method, params = {})
205
+ def presigned_url(method, params = {})
192
206
  presigner = Presigner.new(client: client)
207
+
208
+ if %w(delete head get put).include?(method.to_s)
209
+ method = "#{method}_object".to_sym
210
+ end
211
+
193
212
  presigner.presigned_url(
194
- "#{http_method.downcase}_object",
213
+ method.downcase,
214
+ params.merge(bucket: bucket_name, key: key)
215
+ )
216
+ end
217
+
218
+ # Allows you to create presigned URL requests for S3 operations. This
219
+ # method returns a tuple containing the URL and the signed X-amz-* headers
220
+ # to be used with the presigned url.
221
+ #
222
+ # @example Pre-signed GET URL, valid for one hour
223
+ #
224
+ # obj.presigned_request(:get, expires_in: 3600)
225
+ # #=> ["https://bucket-name.s3.amazonaws.com/object-key?...", {}]
226
+ #
227
+ # @example Pre-signed PUT with a canned ACL
228
+ #
229
+ # # the object uploaded using this URL will be publicly accessible
230
+ # obj.presigned_request(:put, acl: 'public-read')
231
+ # #=> ["https://bucket-name.s3.amazonaws.com/object-key?...",
232
+ # {"x-amz-acl"=>"public-read"}]
233
+ #
234
+ # @param [Symbol] method
235
+ # The S3 operation to generate a presigned request for. Valid values
236
+ # are `:get`, `:put`, `:head`, `:delete`, `:create_multipart_upload`,
237
+ # `:list_multipart_uploads`, `:complete_multipart_upload`,
238
+ # `:abort_multipart_upload`, `:list_parts`, and `:upload_part`.
239
+ #
240
+ # @param [Hash] params
241
+ # Additional request parameters to use when generating the pre-signed
242
+ # request. See the related documentation in {Client} for accepted
243
+ # params.
244
+ #
245
+ # | Method | Client Method |
246
+ # |------------------------------|------------------------------------|
247
+ # | `:get` | {Client#get_object} |
248
+ # | `:put` | {Client#put_object} |
249
+ # | `:head` | {Client#head_object} |
250
+ # | `:delete` | {Client#delete_object} |
251
+ # | `:create_multipart_upload` | {Client#create_multipart_upload} |
252
+ # | `:list_multipart_uploads` | {Client#list_multipart_uploads} |
253
+ # | `:complete_multipart_upload` | {Client#complete_multipart_upload} |
254
+ # | `:abort_multipart_upload` | {Client#abort_multipart_upload} |
255
+ # | `:list_parts` | {Client#list_parts} |
256
+ # | `:upload_part` | {Client#upload_part} |
257
+ #
258
+ # @option params [Boolean] :virtual_host (false) When `true` the
259
+ # presigned URL will use the bucket name as a virtual host.
260
+ #
261
+ # bucket = Aws::S3::Bucket.new('my.bucket.com')
262
+ # bucket.object('key').presigned_request(virtual_host: true)
263
+ # #=> ["http://my.bucket.com/key?...", {}]
264
+ #
265
+ # @option params [Integer] :expires_in (900) Number of seconds before
266
+ # the pre-signed URL expires. This may not exceed one week (604800
267
+ # seconds). Note that the pre-signed URL is also only valid as long as
268
+ # credentials used to sign it are. For example, when using IAM roles,
269
+ # temporary tokens generated for signing also have a default expiration
270
+ # which will affect the effective expiration of the pre-signed URL.
271
+ #
272
+ # @raise [ArgumentError] Raised if `:expires_in` exceeds one week
273
+ # (604800 seconds).
274
+ #
275
+ # @return [String, Hash] A tuple with a presigned URL and headers that
276
+ # should be included with the request.
277
+ #
278
+ def presigned_request(method, params = {})
279
+ presigner = Presigner.new(client: client)
280
+
281
+ if %w(delete head get put).include?(method.to_s)
282
+ method = "#{method}_object".to_sym
283
+ end
284
+
285
+ presigner.presigned_request(
286
+ method.downcase,
195
287
  params.merge(bucket: bucket_name, key: key)
196
288
  )
197
289
  end
@@ -201,16 +293,22 @@ module Aws
201
293
  # s3.bucket('bucket-name').object('obj-key').public_url
202
294
  # #=> "https://bucket-name.s3.amazonaws.com/obj-key"
203
295
  #
204
- # To use virtual hosted bucket url (disables https):
296
+ # To use virtual hosted bucket url.
297
+ # Uses https unless secure: false is set. If the bucket
298
+ # name contains dots (.) then you will need to set secure: false.
205
299
  #
206
- # s3.bucket('my.bucket.com').object('key')
300
+ # s3.bucket('my-bucket.com').object('key')
207
301
  # .public_url(virtual_host: true)
208
- # #=> "http://my.bucket.com/key"
302
+ # #=> "https://my-bucket.com/key"
209
303
  #
210
304
  # @option options [Boolean] :virtual_host (false) When `true`, the bucket
211
305
  # name will be used as the host name. This is useful when you have
212
306
  # a CNAME configured for the bucket.
213
307
  #
308
+ # @option options [Boolean] :secure (true) When `false`, http
309
+ # will be used with virtual_host. This is required when
310
+ # the bucket name has a dot (.) in it.
311
+ #
214
312
  # @return [String]
215
313
  def public_url(options = {})
216
314
  url = URI.parse(bucket.url(options))
@@ -282,8 +380,8 @@ module Aws
282
380
  # # small files are uploaded in a single API call
283
381
  # obj.upload_file('/path/to/file')
284
382
  #
285
- # Files larger than `:multipart_threshold` are uploaded using the
286
- # Amazon S3 multipart upload APIs.
383
+ # Files larger than or equal to `:multipart_threshold` are uploaded
384
+ # using the Amazon S3 multipart upload APIs.
287
385
  #
288
386
  # # large files are automatically split into parts
289
387
  # # and the parts are uploaded in parallel
@@ -302,7 +400,7 @@ module Aws
302
400
  # progress = Proc.new do |bytes, totals|
303
401
  # puts bytes.map.with_index { |b, i| "Part #{i+1}: #{b} / #{totals[i]}"}.join(' ') + "Total: #{100.0 * bytes.sum / totals.sum }%" }
304
402
  # end
305
- # obj.upload_file('/path/to/file')
403
+ # obj.upload_file('/path/to/file', progress_callback: progress)
306
404
  #
307
405
  # @param [String, Pathname, File, Tempfile] source A file on the local
308
406
  # file system that will be uploaded as this object. This can either be
@@ -312,9 +410,10 @@ module Aws
312
410
  # using an open Tempfile, rewind it before uploading or else the object
313
411
  # will be empty.
314
412
  #
315
- # @option options [Integer] :multipart_threshold (15728640) Files larger
316
- # than `:multipart_threshold` are uploaded using the S3 multipart APIs.
317
- # Default threshold is 15MB.
413
+ # @option options [Integer] :multipart_threshold (104857600) Files larger
414
+ # than or equal to `:multipart_threshold` are uploaded using the S3
415
+ # multipart APIs.
416
+ # Default threshold is 100MB.
318
417
  #
319
418
  # @option options [Integer] :thread_count (10) The number of parallel
320
419
  # multipart uploads. This option is not used if the file is smaller than
@@ -365,7 +464,7 @@ module Aws
365
464
  # customizing each range size in multipart_download,
366
465
  # By default, `auto` mode is enabled, which performs multipart_download
367
466
  #
368
- # @option options [String] chunk_size required in get_range mode.
467
+ # @option options [Integer] chunk_size required in get_range mode.
369
468
  #
370
469
  # @option options [Integer] thread_count (10) Customize threads used in
371
470
  # the multipart download.
@@ -29,6 +29,6 @@ require 'aws-sdk-s3/customizations/types/list_object_versions_output'
29
29
  Aws::S3::ObjectVersion::Collection,
30
30
  ].each do |klass|
31
31
  klass.send(:alias_method, :delete, :batch_delete!)
32
- klass.send(:extend, Aws::Deprecations)
32
+ klass.extend Aws::Deprecations
33
33
  klass.send(:deprecated, :delete, use: :batch_delete!)
34
34
  end
@@ -120,7 +120,7 @@ module Aws
120
120
  # attr_reader :encryption_materials
121
121
  #
122
122
  # def key_for(matdesc)
123
- # key_name = JSON.load(matdesc)['key']
123
+ # key_name = JSON.parse(matdesc)['key']
124
124
  # if key = @keys[key_name]
125
125
  # key
126
126
  # else
@@ -165,10 +165,6 @@ module Aws
165
165
  # to initialize the cipher, and the decrypter truncates the
166
166
  # auth tag from the body when writing the final bytes.
167
167
  def authenticated_decrypter(context, cipher, envelope)
168
- if RUBY_VERSION.match(/1.9/)
169
- raise "authenticated decryption not supported by OpenSSL in Ruby version ~> 1.9"
170
- raise Aws::Errors::NonSupportedRubyVersionError, msg
171
- end
172
168
  http_resp = context.http_response
173
169
  content_length = http_resp.headers['content-length'].to_i
174
170
  auth_tag_length = auth_tag_length(envelope)
@@ -157,7 +157,7 @@ module Aws
157
157
  # attr_reader :encryption_materials
158
158
  #
159
159
  # def key_for(matdesc)
160
- # key_name = JSON.load(matdesc)['key']
160
+ # key_name = JSON.parse(matdesc)['key']
161
161
  # if key = @keys[key_name]
162
162
  # key
163
163
  # else
@@ -166,10 +166,6 @@ module Aws
166
166
  # to initialize the cipher, and the decrypter truncates the
167
167
  # auth tag from the body when writing the final bytes.
168
168
  def authenticated_decrypter(context, cipher, envelope)
169
- if RUBY_VERSION.match(/1.9/)
170
- raise "authenticated decryption not supported by OpenSSL in Ruby version ~> 1.9"
171
- raise Aws::Errors::NonSupportedRubyVersionError, msg
172
- end
173
169
  http_resp = context.http_response
174
170
  content_length = http_resp.headers['content-length'].to_i
175
171
  auth_tag_length = auth_tag_length(envelope)
@@ -87,9 +87,9 @@ module Aws
87
87
  ' kms+context. Please configure the client with the' \
88
88
  ' required kms_key_id'
89
89
  else
90
- raise ArgumentError, 'Unsupported wrap-alg: ' \
91
- "#{envelope['x-amz-wrap-alg']}"
92
- end
90
+ raise ArgumentError, 'Unsupported wrap-alg: ' \
91
+ "#{envelope['x-amz-wrap-alg']}"
92
+ end
93
93
  iv = decode64(envelope['x-amz-iv'])
94
94
  Utils.aes_decryption_cipher(:GCM, key, iv)
95
95
  end
@@ -9,10 +9,6 @@ module Aws
9
9
  class EncryptHandler < Seahorse::Client::Handler
10
10
 
11
11
  def call(context)
12
- if RUBY_VERSION.match(/1.9/)
13
- raise "authenticated encryption not supported by OpenSSL in Ruby version ~> 1.9"
14
- raise Aws::Errors::NonSupportedRubyVersionError, msg
15
- end
16
12
  envelope, cipher = context[:encryption][:cipher_provider]
17
13
  .encryption_cipher(
18
14
  kms_encryption_context: context[:encryption][:kms_encryption_context]
@@ -3,7 +3,7 @@
3
3
  # WARNING ABOUT GENERATED CODE
4
4
  #
5
5
  # This file is generated. See the contributing guide for more information:
6
- # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
6
+ # https://github.com/aws/aws-sdk-ruby/blob/version-3/CONTRIBUTING.md
7
7
  #
8
8
  # WARNING ABOUT GENERATED CODE
9
9
 
@@ -29,6 +29,7 @@ module Aws::S3
29
29
  # ## Error Classes
30
30
  # * {BucketAlreadyExists}
31
31
  # * {BucketAlreadyOwnedByYou}
32
+ # * {InvalidObjectState}
32
33
  # * {NoSuchBucket}
33
34
  # * {NoSuchKey}
34
35
  # * {NoSuchUpload}
@@ -61,6 +62,26 @@ module Aws::S3
61
62
  end
62
63
  end
63
64
 
65
+ class InvalidObjectState < ServiceError
66
+
67
+ # @param [Seahorse::Client::RequestContext] context
68
+ # @param [String] message
69
+ # @param [Aws::S3::Types::InvalidObjectState] data
70
+ def initialize(context, message, data = Aws::EmptyStructure.new)
71
+ super(context, message, data)
72
+ end
73
+
74
+ # @return [String]
75
+ def storage_class
76
+ @data[:storage_class]
77
+ end
78
+
79
+ # @return [String]
80
+ def access_tier
81
+ @data[:access_tier]
82
+ end
83
+ end
84
+
64
85
  class NoSuchBucket < ServiceError
65
86
 
66
87
  # @param [Seahorse::Client::RequestContext] context
@@ -3,7 +3,7 @@
3
3
  # WARNING ABOUT GENERATED CODE
4
4
  #
5
5
  # This file is generated. See the contributing guide for more information:
6
- # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
6
+ # https://github.com/aws/aws-sdk-ruby/blob/version-3/CONTRIBUTING.md
7
7
  #
8
8
  # WARNING ABOUT GENERATED CODE
9
9
 
@@ -94,7 +94,12 @@ module Aws
94
94
  if @chunk_size && @chunk_size > file_size
95
95
  raise ArgumentError, ":chunk_size shouldn't exceed total file size."
96
96
  else
97
- @chunk_size || [(file_size.to_f / MAX_PARTS).ceil, MIN_CHUNK_SIZE].max.to_i
97
+ chunk_size = @chunk_size || [
98
+ (file_size.to_f / MAX_PARTS).ceil,
99
+ MIN_CHUNK_SIZE
100
+ ].max.to_i
101
+ chunk_size -= 1 if file_size % chunk_size == 1
102
+ chunk_size
98
103
  end
99
104
  end
100
105
 
@@ -129,7 +134,7 @@ module Aws
129
134
  def write(resp)
130
135
  range, _ = resp.content_range.split(' ').last.split('/')
131
136
  head, _ = range.split('-').map {|s| s.to_i}
132
- IO.write(@path, resp.body.read, head)
137
+ File.write(@path, resp.body.read, head)
133
138
  end
134
139
 
135
140
  def single_request
@@ -7,22 +7,22 @@ module Aws
7
7
  # @api private
8
8
  class FileUploader
9
9
 
10
- FIFTEEN_MEGABYTES = 15 * 1024 * 1024
10
+ ONE_HUNDRED_MEGABYTES = 100 * 1024 * 1024
11
11
 
12
12
  # @param [Hash] options
13
13
  # @option options [Client] :client
14
- # @option options [Integer] :multipart_threshold (15728640)
14
+ # @option options [Integer] :multipart_threshold (104857600)
15
15
  def initialize(options = {})
16
16
  @options = options
17
17
  @client = options[:client] || Client.new
18
18
  @multipart_threshold = options[:multipart_threshold] ||
19
- FIFTEEN_MEGABYTES
19
+ ONE_HUNDRED_MEGABYTES
20
20
  end
21
21
 
22
22
  # @return [Client]
23
23
  attr_reader :client
24
24
 
25
- # @return [Integer] Files larger than this in bytes are uploaded
25
+ # @return [Integer] Files larger than or equal to this in bytes are uploaded
26
26
  # using a {MultipartFileUploader}.
27
27
  attr_reader :multipart_threshold
28
28
 
@@ -32,11 +32,16 @@ module Aws
32
32
  # @option options [Proc] :progress_callback
33
33
  # A Proc that will be called when each chunk of the upload is sent.
34
34
  # It will be invoked with [bytes_read], [total_sizes]
35
+ # @option options [Integer] :thread_count
36
+ # The thread count to use for multipart uploads. Ignored for
37
+ # objects smaller than the multipart threshold.
35
38
  # @return [void]
36
39
  def upload(source, options = {})
37
40
  if File.size(source) >= multipart_threshold
38
41
  MultipartFileUploader.new(@options).upload(source, options)
39
42
  else
43
+ # remove multipart parameters not supported by put_object
44
+ options.delete(:thread_count)
40
45
  put_object(source, options)
41
46
  end
42
47
  end
@@ -4,7 +4,6 @@ require 'set'
4
4
  require 'time'
5
5
  require 'openssl'
6
6
  require 'cgi'
7
- require 'webrick/httputils'
8
7
  require 'aws-sdk-core/query'
9
8
 
10
9
  module Aws
@@ -157,33 +156,24 @@ module Aws
157
156
  end
158
157
 
159
158
  def uri_escape(s)
160
-
161
159
  #URI.escape(s)
162
160
 
163
- # URI.escape is deprecated, replacing it with escape from webrick
164
- # to squelch the massive number of warnings generated from Ruby.
165
- # The following script was used to determine the differences
166
- # between the various escape methods available. The webrick
167
- # escape only had two differences and it is available in the
168
- # standard lib.
169
- #
170
- # (0..255).each {|c|
171
- # s = [c].pack("C")
172
- # e = [
173
- # CGI.escape(s),
174
- # ERB::Util.url_encode(s),
175
- # URI.encode_www_form_component(s),
176
- # WEBrick::HTTPUtils.escape_form(s),
177
- # WEBrick::HTTPUtils.escape(s),
178
- # URI.escape(s),
179
- # ]
180
- # next if e.uniq.length == 1
181
- # puts("%5s %5s %5s %5s %5s %5s %5s" % ([s.inspect] + e))
182
- # }
183
- #
184
- WEBrick::HTTPUtils.escape(s).gsub('%5B', '[').gsub('%5D', ']')
161
+ # (0..255).each {|c|
162
+ # s = [c].pack("C")
163
+ # e = [
164
+ # CGI.escape(s),
165
+ # ERB::Util.url_encode(s),
166
+ # URI.encode_www_form_component(s),
167
+ # WEBrick::HTTPUtils.escape_form(s),
168
+ # WEBrick::HTTPUtils.escape(s),
169
+ # URI.escape(s),
170
+ # URI::DEFAULT_PARSER.escape(s)
171
+ # ]
172
+ # next if e.uniq.length == 1
173
+ # puts("%5s %5s %5s %5s %5s %5s %5s %5s" % ([s.inspect] + e))
174
+ # }
175
+ URI::DEFAULT_PARSER.escape(s)
185
176
  end
186
-
187
177
  end
188
178
  end
189
179
  end
@@ -21,6 +21,10 @@ module Aws
21
21
  Client.api.operation(:create_multipart_upload).input.shape.member_names
22
22
  )
23
23
 
24
+ COMPLETE_OPTIONS = Set.new(
25
+ Client.api.operation(:complete_multipart_upload).input.shape.member_names
26
+ )
27
+
24
28
  # @api private
25
29
  UPLOAD_PART_OPTIONS = Set.new(
26
30
  Client.api.operation(:upload_part).input.shape.member_names
@@ -42,7 +46,7 @@ module Aws
42
46
  # @option options [Proc] :progress_callback
43
47
  # A Proc that will be called when each chunk of the upload is sent.
44
48
  # It will be invoked with [bytes_read], [total_sizes]
45
- # @return [void]
49
+ # @return [Seahorse::Client::Response] - the CompleteMultipartUploadResponse
46
50
  def upload(source, options = {})
47
51
  if File.size(source) < MIN_PART_SIZE
48
52
  raise ArgumentError, FILE_TOO_SMALL
@@ -61,10 +65,10 @@ module Aws
61
65
 
62
66
  def complete_upload(upload_id, parts, options)
63
67
  @client.complete_multipart_upload(
64
- bucket: options[:bucket],
65
- key: options[:key],
66
- upload_id: upload_id,
67
- multipart_upload: { parts: parts }
68
+ **complete_opts(options).merge(
69
+ upload_id: upload_id,
70
+ multipart_upload: { parts: parts }
71
+ )
68
72
  )
69
73
  end
70
74
 
@@ -123,6 +127,13 @@ module Aws
123
127
  end
124
128
  end
125
129
 
130
+ def complete_opts(options)
131
+ COMPLETE_OPTIONS.inject({}) do |hash, key|
132
+ hash[key] = options[key] if options.key?(key)
133
+ hash
134
+ end
135
+ end
136
+
126
137
  def upload_part_opts(options)
127
138
  UPLOAD_PART_OPTIONS.inject({}) do |hash, key|
128
139
  hash[key] = options[key] if options.key?(key)
@@ -147,7 +158,15 @@ module Aws
147
158
  end
148
159
  resp = @client.upload_part(part)
149
160
  part[:body].close
150
- completed.push(etag: resp.etag, part_number: part[:part_number])
161
+ completed_part = {etag: resp.etag, part_number: part[:part_number]}
162
+
163
+ # get the requested checksum from the response
164
+ if part[:checksum_algorithm]
165
+ k = "checksum_#{part[:checksum_algorithm].downcase}".to_sym
166
+ completed_part[k] = resp[k]
167
+ end
168
+
169
+ completed.push(completed_part)
151
170
  end
152
171
  nil
153
172
  rescue => error
@@ -224,4 +243,4 @@ module Aws
224
243
  end
225
244
  end
226
245
  end
227
- end
246
+ end