Load files to Azure file storage using python

I'm using azure file storage for data persistence of several container instances, on that side, it is working fine. I issue I have is that some of the containers read data that I load manually to the File storage via web interface. I need to update this to be able to load the files from python but I'm not finding any examples of how to to this.

There is a github repo from Azure https://github.com/Azure/azure-storage-python that is supposed to handle that, but I'm not finding any examples there, only the source code. On medium and other sites I have found tutorials for using Blob but I haven't found any for Files

Upvotes: 0

Views: 3839

Answers (1)

Charles Xu
Charles Xu

Reputation: 31452

As the comment said, the samples show the action for the file share. I assume that you want to read the content from the file which in the file share, the same code below:

from azure.storage.file import FileService

storageAccount='xxxxx'
accountKey='xxxxx'

file_service = FileService(account_name=storageAccount, account_key=accountKey)

# if the file in the root path of the share, please let the directory name as ''
file = file_service.get_file_to_text(share_name, directory_name, file_name)
print(file.content)

This code gets the file with type File.

Upvotes: 2

Related Questions