@@ -49,7 +49,7 @@ def initialize(account_name:, access_key: nil, principal_id: nil, container:, ho
49
49
# [+:block_size+]
50
50
# 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+
51
51
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 )
53
53
put_blob_multiple ( key , content , **options )
54
54
else
55
55
put_blob_single ( key , content , **options )
@@ -309,7 +309,7 @@ def append_blob_block(key, content, options = {})
309
309
uri . query = URI . encode_www_form ( comp : "appendblock" )
310
310
311
311
headers = {
312
- "Content-Length" : content . size ,
312
+ "Content-Length" : content_size ( content ) ,
313
313
"Content-Type" : options [ :content_type ] ,
314
314
"Content-MD5" : options [ :content_md5 ] ,
315
315
} . merge ( additional_headers ( options ) )
@@ -333,7 +333,7 @@ def put_blob_block(key, index, content, options = {})
333
333
uri . query = URI . encode_www_form ( comp : "block" , blockid : block_id )
334
334
335
335
headers = {
336
- "Content-Length" : content . size ,
336
+ "Content-Length" : content_size ( content ) ,
337
337
"Content-Type" : options [ :content_type ] ,
338
338
"Content-MD5" : options [ :content_md5 ] ,
339
339
} . merge ( additional_headers ( options ) )
@@ -361,7 +361,7 @@ def commit_blob_blocks(key, block_ids, options = {})
361
361
uri . query = URI . encode_www_form ( comp : "blocklist" )
362
362
363
363
headers = {
364
- "Content-Length" : content . size ,
364
+ "Content-Length" : content_size ( content ) ,
365
365
"Content-Type" : options [ :content_type ] ,
366
366
"x-ms-blob-content-md5" : options [ :content_md5 ] ,
367
367
"x-ms-blob-content-disposition" : options [ :content_disposition ] ,
@@ -384,7 +384,7 @@ def generate_block_id(index)
384
384
def put_blob_multiple ( key , content , options = { } )
385
385
content = StringIO . new ( content ) if content . is_a? String
386
386
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
388
388
block_ids = block_count . times . map do |i |
389
389
put_blob_block ( key , i , content . read ( block_size ) )
390
390
end
@@ -398,7 +398,7 @@ def put_blob_single(key, content, options = {})
398
398
399
399
headers = {
400
400
"x-ms-blob-type" : "BlockBlob" ,
401
- "Content-Length" : content . size ,
401
+ "Content-Length" : content_size ( content ) ,
402
402
"Content-Type" : options [ :content_type ] ,
403
403
"x-ms-blob-content-md5" : options [ :content_md5 ] ,
404
404
"x-ms-blob-content-disposition" : options [ :content_disposition ] ,
@@ -407,6 +407,14 @@ def put_blob_single(key, content, options = {})
407
407
Http . new ( uri , headers , signer :, **options . slice ( :metadata , :tags ) ) . put ( content . read )
408
408
end
409
409
410
+ def content_size ( content )
411
+ if content . respond_to? ( :bytesize )
412
+ content . bytesize
413
+ else
414
+ content . size
415
+ end
416
+ end
417
+
410
418
def host
411
419
@host ||= "https://#{ account_name } .blob.#{ CLOUD_REGIONS_SUFFIX [ cloud_regions ] } "
412
420
end
0 commit comments