Skip to content

Instantly share code, notes, and snippets.

@goldsail
Created June 6, 2020 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goldsail/ca86edcf3c2765ad2be8ae8e0649d036 to your computer and use it in GitHub Desktop.
Save goldsail/ca86edcf3c2765ad2be8ae8e0649d036 to your computer and use it in GitHub Desktop.
Azure REST API
import string
import io
import requests
content = 'hello'
filename = 'test.txt'
account = 'example'
container = 'default'
blob_type = 'BlockBlob'
# This token can be obtained from Azure Portal -> Storage Account -> Shared access signature
token = r'?sv=2019-10-10&ss=b&srt=o&sp=rwdlacx&se=2021-07-01T06:59:59Z&st=2020-06-06T05:20:31Z&spr=https&sig=[YOUR_SIGNATURE_HERE]'
url = f'https://{account}.blob.core.windows.net/{container}/{filename}'
headers = {
'Content-Length': str(len(content)),
'Content-Type': 'text/plain',
'x-ms-blob-type': 'BlockBlob'
}
resp = requests.put(url + token, headers=headers, data=content)
print(resp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment