diff --git a/.gitignore b/.gitignore index 78b325a..d49554e 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/lib/paperclip-azure.rb b/lib/paperclip-azure.rb index 753b093..156cd9a 100644 --- a/lib/paperclip-azure.rb +++ b/lib/paperclip-azure.rb @@ -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 diff --git a/lib/paperclip/storage/azure.rb b/lib/paperclip/storage/azure.rb index 9a922bb..0149a33 100644 --- a/lib/paperclip/storage/azure.rb +++ b/lib/paperclip/storage/azure.rb @@ -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)}") @@ -221,7 +220,6 @@ 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 @@ -229,7 +227,7 @@ def save_blob(container_name, storage_path, file, write_options) 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 @@ -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)