Skip to content

Instantly share code, notes, and snippets.

@shackbarth
Created November 16, 2018 14:11
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 shackbarth/3a94e6584c84d4d1cd216add387b0830 to your computer and use it in GitHub Desktop.
Save shackbarth/3a94e6584c84d4d1cd216add387b0830 to your computer and use it in GitHub Desktop.
import os
from azure.storage.blob import BlockBlobService, PublicAccess
import argparse
#
# Usage: python python/azure-sas-send-blob.py --account_name ursahealthstorage
# --sas_token "st=2018...&se=2018...&sp=r...&sv=2018...&sr=c&sig=2S...E%3D"
# --container_name ursahealth-datasource --local_filename /path/to/my_test.csv --blob_name my_test.csv
#
# Note that the SAS Token is the querystring of the SAS URL (i.e. everything after the ?)
# You can use the blob_name parameter to rename the file into the container, but you probably won't want to
#
parser = argparse.ArgumentParser()
parser.add_argument('--account_name')
parser.add_argument('--sas_token')
parser.add_argument('--container_name')
parser.add_argument('--local_filename')
parser.add_argument('--blob_name')
cli_params = parser.parse_args()
def main():
try:
block_blob_service = BlockBlobService(account_name=cli_params.account_name, sas_token=cli_params.sas_token)
block_blob_service.create_blob_from_path(cli_params.container_name, cli_params.blob_name, cli_params.local_filename)
print("Successfully sent file {}".format(cli_params.blob_name))
except Exception as e:
print(e)
exit(1)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment