提交 46025aac 编写于 作者: G George Claghorn

Fix uploading Tempfiles to Azure Storage

Closes #32530.
上级 35e1a426
......@@ -20,7 +20,7 @@ def initialize(storage_account_name:, storage_access_key:, container:)
def upload(key, io, checksum: nil)
instrument :upload, key: key, checksum: checksum do
begin
blobs.create_block_blob(container, key, io, content_md5: checksum)
blobs.create_block_blob(container, key, IO.try_convert(io) || io, content_md5: checksum)
rescue Azure::Core::Http::HTTPError
raise ActiveStorage::IntegrityError
end
......
......@@ -16,6 +16,23 @@ class ActiveStorage::Service::AzureStorageServiceTest < ActiveSupport::TestCase
assert_match(/(\S+)&rscd=inline%3B\+filename%3D%22avatar\.png%22%3B\+filename\*%3DUTF-8%27%27avatar\.png&rsct=image%2Fpng/, url)
assert_match SERVICE_CONFIGURATIONS[:azure][:container], url
end
test "uploading a tempfile" do
begin
key = SecureRandom.base58(24)
data = "Something else entirely!"
Tempfile.open do |file|
file.write(data)
file.rewind
@service.upload(key, file)
end
assert_equal data, @service.download(key)
ensure
@service.delete(key)
end
end
end
else
puts "Skipping Azure Storage Service tests because no Azure configuration was supplied"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册