Using the Python3 requests module and the PUT Blob Azure Rest API to upload a file into Azure storage:
file_name = "testfile.txt"
url = f"https://<storageaccount>.blob.core.windows.net/test/{file_name}?sv=<SASTOKEN>"
with open(file_name, 'rb') as data:
headers = {
'x-ms-version': '2019-02-02',
'x-ms-date': 'Mon, 30 Mar 2020 17:20:00 GMT',
'x-ms-blob-type': 'BlockBlob',
'x-ms-access-tier': 'Cool'
}
response = requests.put(
url,
data=data,
headers=headers
)
print(f"Response {response}")
This works for files with content. But, when trying to upload an empty file I get a 400
response code. How can I upload an empty file?