I am trying to copy an image from file storage to blob storage using python but unable to get it to work. I have based it on this node.js example Copy Azure File Share to Blob with node.js. The exception I get when running the python code locally is shown below.
azure.core.exceptions.ResourceNotFoundError: This request is not authorized to perform this operation using this resource type.
Here is a snippet of the python code.
sas_token = generate_account_sas(
account_name=account_name,
account_key=account_key,
resource_types=ResourceTypes(service=True),
permission=AccountSasPermissions(read=True),
expiry=datetime.utcnow() + timedelta(hours=1)
)
blob_service_client = BlobServiceClient(account_url=blob_uri, credential=account_key)
container_client = blob_service_client.get_container_client("event")
share_directory_client = ShareDirectoryClient.from_connection_string(conn_str=conn_string,
share_name="test-share",
directory_path="")
dir_list = list(share_directory_client.list_directories_and_files())
logging.info(f"list directories and files : {dir_list}")
for item in dir_list:
if item['is_directory']:
pass
else:
fileClient = share_directory_client.get_file_client(item['name'])
source_url = fileClient.url + "?" + sas_token
logging.info(f"{source_url}")
container_client.get_blob_client(item['name']).start_copy_from_url(source_url)
The source url created using the SAS token is shown below.
https://<STORAGE_NAME>.file.core.windows.net/test-share/test.jpg?se=2021-10-01T05%3A46%3A22Z&sp=r&sv=2020-10-02&ss=f&srt=s&sig=<signature>