0
votes

Let's say there is blob in Azure Blob Storage, which I want to download as byte[]. This can be achieved by getting the reference to the blob and downloading as shown below in the below snippet:

CloudBlobContainer container = getCloudBlobContainer(containerName);
CloudBlockBlob blob = container.getBlockBlobReference(blobName);

Now I can use blob.downloadToByteArray(byte[] buffer, int bufferOffset) I have gone through some links where it is suggested that buffer is to be initialised with the size which is more than sum of the blob size and bufferOffset. Now bufferOffset will be 0 but how do I derive stored blob size. Any suggestion here.

1
Is that you want to get the blob size?Jim Xu
I don't want to get the blob size in the first place as I want to download the whole content.Rax
If you want to download the whole content, you can try to use downloadToFile method :docs.microsoft.com/en-us/java/api/…Jim Xu
I am aware of those options, I need byte[] so do not want to download it as file. For that sake, I can very well upload text and download text and then convert text (String) to byte[].Rax
Since there is a method by name downloadToByteArray available, I wanted to use this.Rax

1 Answers

0
votes

If you want to get blob size with java sdk, please refer to the following code

CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
        CloudBlobClient serviceClient = account.createCloudBlobClient();

        CloudBlobContainer container = serviceClient.getContainerReference("test1");

        CloudBlob blob = container.getBlobReferenceFromServer("server.js");
        long size =blob.getProperties().getLength();
        System.out.println(size);

enter image description here

For more details, please refer to the document and the issue