Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send files in chunks #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/carrierwave/storage/azure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,21 @@ 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 = []

until file_to_send.eof?
block_id = Base64.urlsafe_encode64(SecureRandom.uuid)

@content = file_to_send.read 4194304 # Send 4MB chunk
@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
end

Expand Down