SHA in blob storage

William A Wang 236 Reputation points
2020-07-15T04:37:02.52+00:00

I need to determine the version of local file is latest, if the file is not the latest then I should download the file from blob, I searched some sample which is to using the memory stream but it need to download the entire file, most of our file size is from 500MB to 10+GB, so is that possible to calculate the SHA is azure side so I can compare the SHA with local version.
Thanks.

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,511 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. deherman-MSFT 34,041 Reputation points Microsoft Employee
    2020-07-15T20:03:31.873+00:00

    @William A Wang Apologies for the delayed response here. Azure blob storage stores the MD5 hash (not SHA1) of the blob automatically as the Content-MD5 property while putting the blob. For larger files storage does not calculate the MD5 hash of the full blob because each block is written separately. You can work around this by calculating and manually setting the md5 hash when uploading your files. Note the md5 hash is in base64. See the example below for how to upload a blob while calculating and setting the Content-MD5 property:

    az storage blob upload -c test -n md5test -f ./test.img --content-md5 `cat test.img | openssl dgst -md5 -binary | base64`  
    

    --------------

    Please do not forget to "Accept the answer" and Upvote on the post that helps you, this can be beneficial to other community members.

    1 person found this answer helpful.