Skip to content Skip to sidebar Skip to footer

Azure Put Blob Api Returns With A Non-matching Size Of File In Canonicalized Header

I am trying to upload a blob (pdf) file from my laptop to a container in Azure storage account. I found it to be working but with one glitch. I am calculating the file size using:

Solution 1:

As mentioned in the comments, the reason you're getting the content length mismatched header is because instead of uploading the file, you're uploading an object which contains file contents and that is causing the content length to increase.

Please change the following line of codes:

files = {'file': open(fd, 'rb')}
result = requests.put(url = URI, headers = header, files = files)

to something like:

data = open(fd, 'rb') as stream 
result = requests.put(url = URI, headers = header, data = data)

And now you're only uploading the file contents.

Post a Comment for "Azure Put Blob Api Returns With A Non-matching Size Of File In Canonicalized Header"