How to know the size of an Azure blob object via Python Azure SDK











up vote
0
down vote

favorite












Following the Microsoft Azure documentation for Python developers. The azure.storage.blob.models.Blob class does have a private method called __sizeof__(). But it returns a constant value of 16, whether the blob is empty (0 byte) or 1 GB. Is there any method/attribute of a blob object with which I can dynamically check the size of the object?



To be clearer, this is how my source code looks like.



for i in blobService.list_blobs(container_name=container, prefix=path):
if i.name.endswith('.json') and r'CIJSONTM.json/part' in i.name:
#do some stuffs


However, the data pool contains many empty blobs having legitimate names, and before I #do some stuffs, I want to have an additional check on the size to judge whether I am dealing with an empty blob.



Also, bonus for what exactly does the __sizeof__() method give, if not the size of the blob object?










share|improve this question






















  • Your linked blob class has a metadata property - can you check what's in there? Perhaps, as per your example: i.metadata['size'] or the equivalent python to get a value from a named key value pair?
    – user3012708
    Nov 19 at 8:27















up vote
0
down vote

favorite












Following the Microsoft Azure documentation for Python developers. The azure.storage.blob.models.Blob class does have a private method called __sizeof__(). But it returns a constant value of 16, whether the blob is empty (0 byte) or 1 GB. Is there any method/attribute of a blob object with which I can dynamically check the size of the object?



To be clearer, this is how my source code looks like.



for i in blobService.list_blobs(container_name=container, prefix=path):
if i.name.endswith('.json') and r'CIJSONTM.json/part' in i.name:
#do some stuffs


However, the data pool contains many empty blobs having legitimate names, and before I #do some stuffs, I want to have an additional check on the size to judge whether I am dealing with an empty blob.



Also, bonus for what exactly does the __sizeof__() method give, if not the size of the blob object?










share|improve this question






















  • Your linked blob class has a metadata property - can you check what's in there? Perhaps, as per your example: i.metadata['size'] or the equivalent python to get a value from a named key value pair?
    – user3012708
    Nov 19 at 8:27













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Following the Microsoft Azure documentation for Python developers. The azure.storage.blob.models.Blob class does have a private method called __sizeof__(). But it returns a constant value of 16, whether the blob is empty (0 byte) or 1 GB. Is there any method/attribute of a blob object with which I can dynamically check the size of the object?



To be clearer, this is how my source code looks like.



for i in blobService.list_blobs(container_name=container, prefix=path):
if i.name.endswith('.json') and r'CIJSONTM.json/part' in i.name:
#do some stuffs


However, the data pool contains many empty blobs having legitimate names, and before I #do some stuffs, I want to have an additional check on the size to judge whether I am dealing with an empty blob.



Also, bonus for what exactly does the __sizeof__() method give, if not the size of the blob object?










share|improve this question













Following the Microsoft Azure documentation for Python developers. The azure.storage.blob.models.Blob class does have a private method called __sizeof__(). But it returns a constant value of 16, whether the blob is empty (0 byte) or 1 GB. Is there any method/attribute of a blob object with which I can dynamically check the size of the object?



To be clearer, this is how my source code looks like.



for i in blobService.list_blobs(container_name=container, prefix=path):
if i.name.endswith('.json') and r'CIJSONTM.json/part' in i.name:
#do some stuffs


However, the data pool contains many empty blobs having legitimate names, and before I #do some stuffs, I want to have an additional check on the size to judge whether I am dealing with an empty blob.



Also, bonus for what exactly does the __sizeof__() method give, if not the size of the blob object?







python azure azure-storage-blobs sizeof azure-sdk-python






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 7:04









Della

243110




243110












  • Your linked blob class has a metadata property - can you check what's in there? Perhaps, as per your example: i.metadata['size'] or the equivalent python to get a value from a named key value pair?
    – user3012708
    Nov 19 at 8:27


















  • Your linked blob class has a metadata property - can you check what's in there? Perhaps, as per your example: i.metadata['size'] or the equivalent python to get a value from a named key value pair?
    – user3012708
    Nov 19 at 8:27
















Your linked blob class has a metadata property - can you check what's in there? Perhaps, as per your example: i.metadata['size'] or the equivalent python to get a value from a named key value pair?
– user3012708
Nov 19 at 8:27




Your linked blob class has a metadata property - can you check what's in there? Perhaps, as per your example: i.metadata['size'] or the equivalent python to get a value from a named key value pair?
– user3012708
Nov 19 at 8:27












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted











I want to have an additional check on the size to judge whether I am dealing with an empty blob.




We could use the BlobProperties().content_length to check whether it is a empty blob.



BlockBlobService.get_blob_properties(block_blob_service,container_name,blob_name).properties.content_length


The following is the demo code how to get the blob content_length :



from azure.storage.blob import BlockBlobService
block_blob_service = BlockBlobService(account_name='accoutName', account_key='accountKey')
container_name ='containerName'
block_blob_service.create_container(container_name)
generator = block_blob_service.list_blobs(container_name)
for blob in generator:
length = BlockBlobService.get_blob_properties(block_blob_service,container_name,blob.name).properties.content_length
print("t Blob name: " + blob.name)
print(length)





share|improve this answer





















  • Thanks. Curiously, the method is absent in the documentation it seems. And what does the ' __sizeof__()' method do here?
    – Della
    Nov 20 at 9:33










  • Could you please add more information about __sizeof__()? Have you looked into the source code?
    – Tom Sun
    Nov 20 at 9:37













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369766%2fhow-to-know-the-size-of-an-azure-blob-object-via-python-azure-sdk%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted











I want to have an additional check on the size to judge whether I am dealing with an empty blob.




We could use the BlobProperties().content_length to check whether it is a empty blob.



BlockBlobService.get_blob_properties(block_blob_service,container_name,blob_name).properties.content_length


The following is the demo code how to get the blob content_length :



from azure.storage.blob import BlockBlobService
block_blob_service = BlockBlobService(account_name='accoutName', account_key='accountKey')
container_name ='containerName'
block_blob_service.create_container(container_name)
generator = block_blob_service.list_blobs(container_name)
for blob in generator:
length = BlockBlobService.get_blob_properties(block_blob_service,container_name,blob.name).properties.content_length
print("t Blob name: " + blob.name)
print(length)





share|improve this answer





















  • Thanks. Curiously, the method is absent in the documentation it seems. And what does the ' __sizeof__()' method do here?
    – Della
    Nov 20 at 9:33










  • Could you please add more information about __sizeof__()? Have you looked into the source code?
    – Tom Sun
    Nov 20 at 9:37

















up vote
1
down vote



accepted











I want to have an additional check on the size to judge whether I am dealing with an empty blob.




We could use the BlobProperties().content_length to check whether it is a empty blob.



BlockBlobService.get_blob_properties(block_blob_service,container_name,blob_name).properties.content_length


The following is the demo code how to get the blob content_length :



from azure.storage.blob import BlockBlobService
block_blob_service = BlockBlobService(account_name='accoutName', account_key='accountKey')
container_name ='containerName'
block_blob_service.create_container(container_name)
generator = block_blob_service.list_blobs(container_name)
for blob in generator:
length = BlockBlobService.get_blob_properties(block_blob_service,container_name,blob.name).properties.content_length
print("t Blob name: " + blob.name)
print(length)





share|improve this answer





















  • Thanks. Curiously, the method is absent in the documentation it seems. And what does the ' __sizeof__()' method do here?
    – Della
    Nov 20 at 9:33










  • Could you please add more information about __sizeof__()? Have you looked into the source code?
    – Tom Sun
    Nov 20 at 9:37















up vote
1
down vote



accepted







up vote
1
down vote



accepted







I want to have an additional check on the size to judge whether I am dealing with an empty blob.




We could use the BlobProperties().content_length to check whether it is a empty blob.



BlockBlobService.get_blob_properties(block_blob_service,container_name,blob_name).properties.content_length


The following is the demo code how to get the blob content_length :



from azure.storage.blob import BlockBlobService
block_blob_service = BlockBlobService(account_name='accoutName', account_key='accountKey')
container_name ='containerName'
block_blob_service.create_container(container_name)
generator = block_blob_service.list_blobs(container_name)
for blob in generator:
length = BlockBlobService.get_blob_properties(block_blob_service,container_name,blob.name).properties.content_length
print("t Blob name: " + blob.name)
print(length)





share|improve this answer













I want to have an additional check on the size to judge whether I am dealing with an empty blob.




We could use the BlobProperties().content_length to check whether it is a empty blob.



BlockBlobService.get_blob_properties(block_blob_service,container_name,blob_name).properties.content_length


The following is the demo code how to get the blob content_length :



from azure.storage.blob import BlockBlobService
block_blob_service = BlockBlobService(account_name='accoutName', account_key='accountKey')
container_name ='containerName'
block_blob_service.create_container(container_name)
generator = block_blob_service.list_blobs(container_name)
for blob in generator:
length = BlockBlobService.get_blob_properties(block_blob_service,container_name,blob.name).properties.content_length
print("t Blob name: " + blob.name)
print(length)






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 8:24









Tom Sun

15.9k2921




15.9k2921












  • Thanks. Curiously, the method is absent in the documentation it seems. And what does the ' __sizeof__()' method do here?
    – Della
    Nov 20 at 9:33










  • Could you please add more information about __sizeof__()? Have you looked into the source code?
    – Tom Sun
    Nov 20 at 9:37




















  • Thanks. Curiously, the method is absent in the documentation it seems. And what does the ' __sizeof__()' method do here?
    – Della
    Nov 20 at 9:33










  • Could you please add more information about __sizeof__()? Have you looked into the source code?
    – Tom Sun
    Nov 20 at 9:37


















Thanks. Curiously, the method is absent in the documentation it seems. And what does the ' __sizeof__()' method do here?
– Della
Nov 20 at 9:33




Thanks. Curiously, the method is absent in the documentation it seems. And what does the ' __sizeof__()' method do here?
– Della
Nov 20 at 9:33












Could you please add more information about __sizeof__()? Have you looked into the source code?
– Tom Sun
Nov 20 at 9:37






Could you please add more information about __sizeof__()? Have you looked into the source code?
– Tom Sun
Nov 20 at 9:37




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369766%2fhow-to-know-the-size-of-an-azure-blob-object-via-python-azure-sdk%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin