This is a follow up question to my previous question, I am now trying to use PutPage API to upload the file as one chunk. The first part that reserves a space works. I get an error in the second API call saying something is wrong with x-ms-range
value
import os
import http.client
from urllib.parse import urlparse
sas_uri = '<SAS URI>'
uri = urlparse(sas_uri)
conn = http.client.HTTPSConnection(uri.hostname, port=uri.port, timeout=3000)
file_path = r"C:\Users\user\Downloads\npp.Installer.exe"
with open(file_path, 'rb') as reader:
file = reader.read()
file_size = os.stat(file_path).st_size
block_size = file_size
boundary = block_size % 512
if boundary != 0:
block_size = block_size + 512 - boundary
# Reserve a block space
headers = {
'Content-Type': 'application/octet-stream',
'Content-Length': 0,
'x-ms-blob-type': 'PageBlob',
'x-ms-blob-content-length': block_size
}
conn.request('PUT', sas_uri, '', headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
# Upload the file
headers = {
'Content-Type': 'application/octet-stream',
'Content-Length': file_size,
'x-ms-blob-type': 'PageBlob',
'x-ms-page-write': 'update',
'x-ms-range': f'bytes=0-{file_size-1}'
}
conn.request('PUT', sas_uri + '&comp=page', file, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Error:
<?xml version="1.0" encoding="utf-8"?> <Error><Code>InvalidHeaderValue</Code><Message>The value for one of the HTTP headers is not in the correct format. RequestId:c3c776d3-e01c-00b7-80de-9386a5000000 Time:2021-08-18T03:11:14.5181971Z</Message><HeaderName>x-ms-range</HeaderName><HeaderValue>bytes=0-3991191</HeaderValue></Error>