Fix S3 multipart uploads when threshold is larger than file

This commit is contained in:
Matt Muller 2020-12-11 13:26:40 -08:00 committed by GitHub
parent 3e5d504f78
commit 4b44d4c0e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -16,7 +16,7 @@ module ActiveStorage
@client = Aws::S3::Resource.new(**options)
@bucket = @client.bucket(bucket)
@multipart_upload_threshold = upload.fetch(:multipart_threshold, 100.megabytes)
@multipart_upload_threshold = upload.delete(:multipart_threshold) || 100.megabytes
@public = public
@upload_options = upload

View File

@ -156,6 +156,20 @@ if SERVICE_CONFIGURATIONS[:s3]
end
end
test "uploading a small object with multipart_threshold configured" do
service = build_service(upload: { multipart_threshold: 5.megabytes })
begin
key = SecureRandom.base58(24)
data = SecureRandom.bytes(3.megabytes)
service.upload key, StringIO.new(data), checksum: Digest::MD5.base64digest(data)
assert data == service.download(key)
ensure
service.delete key
end
end
private
def build_service(configuration)
ActiveStorage::Service.configure :s3, SERVICE_CONFIGURATIONS.deep_merge(s3: configuration)