@@ -49,7 +49,7 @@ def initialize(account_name:, access_key: nil, principal_id: nil, container:, ho
4949 # [+:block_size+]
5050 # Block size in bytes, can be used to force the method to split the upload in smaller chunk. Defaults to +AzureBlob::DEFAULT_BLOCK_SIZE+ and cannot be bigger than +AzureBlob::MAX_UPLOAD_SIZE+
5151 def create_block_blob ( key , content , options = { } )
52- if content . size > ( options [ :block_size ] || DEFAULT_BLOCK_SIZE )
52+ if content_size ( content ) > ( options [ :block_size ] || DEFAULT_BLOCK_SIZE )
5353 put_blob_multiple ( key , content , **options )
5454 else
5555 put_blob_single ( key , content , **options )
@@ -309,7 +309,7 @@ def append_blob_block(key, content, options = {})
309309 uri . query = URI . encode_www_form ( comp : "appendblock" )
310310
311311 headers = {
312- "Content-Length" : content . size ,
312+ "Content-Length" : content_size ( content ) ,
313313 "Content-Type" : options [ :content_type ] ,
314314 "Content-MD5" : options [ :content_md5 ] ,
315315 } . merge ( additional_headers ( options ) )
@@ -333,7 +333,7 @@ def put_blob_block(key, index, content, options = {})
333333 uri . query = URI . encode_www_form ( comp : "block" , blockid : block_id )
334334
335335 headers = {
336- "Content-Length" : content . size ,
336+ "Content-Length" : content_size ( content ) ,
337337 "Content-Type" : options [ :content_type ] ,
338338 "Content-MD5" : options [ :content_md5 ] ,
339339 } . merge ( additional_headers ( options ) )
@@ -361,7 +361,7 @@ def commit_blob_blocks(key, block_ids, options = {})
361361 uri . query = URI . encode_www_form ( comp : "blocklist" )
362362
363363 headers = {
364- "Content-Length" : content . size ,
364+ "Content-Length" : content_size ( content ) ,
365365 "Content-Type" : options [ :content_type ] ,
366366 "x-ms-blob-content-md5" : options [ :content_md5 ] ,
367367 "x-ms-blob-content-disposition" : options [ :content_disposition ] ,
@@ -384,7 +384,7 @@ def generate_block_id(index)
384384 def put_blob_multiple ( key , content , options = { } )
385385 content = StringIO . new ( content ) if content . is_a? String
386386 block_size = options [ :block_size ] || DEFAULT_BLOCK_SIZE
387- block_count = ( content . size . to_f / block_size ) . ceil
387+ block_count = ( content_size ( content ) . to_f / block_size ) . ceil
388388 block_ids = block_count . times . map do |i |
389389 put_blob_block ( key , i , content . read ( block_size ) )
390390 end
@@ -398,7 +398,7 @@ def put_blob_single(key, content, options = {})
398398
399399 headers = {
400400 "x-ms-blob-type" : "BlockBlob" ,
401- "Content-Length" : content . size ,
401+ "Content-Length" : content_size ( content ) ,
402402 "Content-Type" : options [ :content_type ] ,
403403 "x-ms-blob-content-md5" : options [ :content_md5 ] ,
404404 "x-ms-blob-content-disposition" : options [ :content_disposition ] ,
@@ -407,6 +407,10 @@ def put_blob_single(key, content, options = {})
407407 Http . new ( uri , headers , signer :, **options . slice ( :metadata , :tags ) ) . put ( content . read )
408408 end
409409
410+ def content_size ( content )
411+ content . bytesize
412+ end
413+
410414 def host
411415 @host ||= "https://#{ account_name } .blob.#{ CLOUD_REGIONS_SUFFIX [ cloud_regions ] } "
412416 end
0 commit comments