Azure-blob-storage_5.py 659 B

123456789101112131415
  1. def create_blob_from_path(storage_connection_string,container_name):
  2. try:
  3. # Instantiate a new BlobServiceClient and a new ContainerClient
  4. blob_service_client = BlobServiceClient.from_connection_string(storage_connection_string)
  5. container_client = blob_service_client.get_container_client(container_name)
  6. for f in list_files():
  7. with open(f["local_path"], "rb") as data:
  8. blob_client = container_client.get_blob_client(f["file_name"])
  9. blob_client.upload_blob(data,overwrite=True)
  10. return True
  11. except Exception as e:
  12. print(e.message, e.args)
  13. return False