From ac5fa73d45c8bc44ded54624063e8e935fb6dbc3 Mon Sep 17 00:00:00 2001 From: Mike Bajur Date: Thu, 13 Mar 2014 11:01:32 +0100 Subject: [PATCH 1/4] Send file in 4MB chunk --- lib/carrierwave/storage/azure.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/carrierwave/storage/azure.rb b/lib/carrierwave/storage/azure.rb index 42d468b..9081a39 100644 --- a/lib/carrierwave/storage/azure.rb +++ b/lib/carrierwave/storage/azure.rb @@ -32,9 +32,20 @@ def initialize(uploader, connection, path) end def store!(file) - @content = file.read @content_type = file.content_type - @connection.create_block_blob @uploader.azure_container, @path, @content, content_type: @content_type + file_to_send = ::File.open(file.file, 'rb') + blocks = [] + i = 0 + + until file_to_send.eof? + i += 1 + @content = file_to_send.read 4194304 # Send 4MB chunk + @connection.create_blob_block @uploader.azure_container, @path, i.to_s, content + blocks << i.to_s + end + + @connection.commit_blob_blocks @uploader.azure_container, @path, blocks + true end From 9e1175adfeeef2b7b99594a153c8b8625937c72a Mon Sep 17 00:00:00 2001 From: Mike Bajur Date: Thu, 13 Mar 2014 17:05:48 +0100 Subject: [PATCH 2/4] quickfix --- lib/carrierwave/storage/azure.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/carrierwave/storage/azure.rb b/lib/carrierwave/storage/azure.rb index 9081a39..c6fd6c6 100644 --- a/lib/carrierwave/storage/azure.rb +++ b/lib/carrierwave/storage/azure.rb @@ -40,7 +40,7 @@ def store!(file) until file_to_send.eof? i += 1 @content = file_to_send.read 4194304 # Send 4MB chunk - @connection.create_blob_block @uploader.azure_container, @path, i.to_s, content + @connection.create_blob_block @uploader.azure_container, @path, i.to_s, @content blocks << i.to_s end From 82b9296d47fe0ce22a48702c25cb9f0f23ec2548 Mon Sep 17 00:00:00 2001 From: Mike Bajur Date: Tue, 18 Mar 2014 17:26:40 +0100 Subject: [PATCH 3/4] quickfix --- lib/carrierwave/storage/azure.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/carrierwave/storage/azure.rb b/lib/carrierwave/storage/azure.rb index c6fd6c6..054fea2 100644 --- a/lib/carrierwave/storage/azure.rb +++ b/lib/carrierwave/storage/azure.rb @@ -35,15 +35,19 @@ def store!(file) @content_type = file.content_type file_to_send = ::File.open(file.file, 'rb') blocks = [] - i = 0 + + file_size = file_to_send.size.to_f / 2**20 + puts '%.2f' % file_size until file_to_send.eof? - i += 1 + block_id = Base64.urlsafe_encode64(SecureRandom.uuid) + @content = file_to_send.read 4194304 # Send 4MB chunk - @connection.create_blob_block @uploader.azure_container, @path, i.to_s, @content - blocks << i.to_s + @connection.create_blob_block @uploader.azure_container, @path, block_id, @content + blocks << [block_id] end + # Commit block blobs @connection.commit_blob_blocks @uploader.azure_container, @path, blocks true From b300306af471e544262a2e6275c5b188ebd534d2 Mon Sep 17 00:00:00 2001 From: Mike Bajur Date: Tue, 18 Mar 2014 17:27:15 +0100 Subject: [PATCH 4/4] quickfix --- lib/carrierwave/storage/azure.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/carrierwave/storage/azure.rb b/lib/carrierwave/storage/azure.rb index 054fea2..57d9592 100644 --- a/lib/carrierwave/storage/azure.rb +++ b/lib/carrierwave/storage/azure.rb @@ -36,9 +36,6 @@ def store!(file) file_to_send = ::File.open(file.file, 'rb') blocks = [] - file_size = file_to_send.size.to_f / 2**20 - puts '%.2f' % file_size - until file_to_send.eof? block_id = Base64.urlsafe_encode64(SecureRandom.uuid)