Fix S3 multipart uploads when threshold is larger than file
This commit is contained in:
parent
3e5d504f78
commit
4b44d4c0e9
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue