Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
### Ruby ###
*.gem
*.rbc
*.swp
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/spec/debug.log
/test/tmp/
/test/version_tmp/
/tmp/
Expand Down
11 changes: 7 additions & 4 deletions lib/paperclip-azure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

require File.join(File.dirname(__FILE__), 'paperclip', 'storage', 'azure')

module Azure
module Azure::Storage
module Blob
BlobService.class_eval do
def initialize(signer=Core::Auth::SharedKey.new, account_name=Azure.config.storage_account_name)
super(signer, account_name)
@host = Paperclip::Storage::AzureRegion.url_for account_name
original_initialize = instance_method(:initialize)

define_method(:initialize) do |options, &block|
original_initialize.bind(self).(options, &block)
account_name = options[:client].storage_account_name
@host = "https://#{Paperclip::Storage::Azure::Environment.url_for(account_name)}"
end
end
end
Expand Down
6 changes: 2 additions & 4 deletions lib/paperclip/storage/azure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ def create_container

def flush_writes #:nodoc:
@queued_for_write.each do |style, file|
retries = 0
begin
log("saving #{path(style)}")

Expand Down Expand Up @@ -221,15 +220,14 @@ def flush_writes #:nodoc:
end

def save_blob(container_name, storage_path, file, write_options)

if file.size < 64.megabytes
azure_interface.create_block_blob container_name, storage_path, file.read, write_options
else
blocks = []; count = 0
while data = file.read(4.megabytes)
block_id = "block_#{(count += 1).to_s.rjust(5, '0')}"

azure_interface.create_blob_block container_name, storage_path, block_id, data
azure_interface.put_blob_block container_name, storage_path, block_id, data

blocks << [block_id]
end
Expand All @@ -254,7 +252,7 @@ def flush_deletes #:nodoc:
def copy_to_local_file(style, local_dest_path)
log("copying #{path(style)} to local file #{local_dest_path}")

blob, content = azure_interface.get_blob(container_name, path(style).sub(%r{\A/},''))
_, content = azure_interface.get_blob(container_name, path(style).sub(%r{\A/},''))

::File.open(local_dest_path, 'wb') do |local_file|
local_file.write(content)
Expand Down