将文件保存到Azure Blob存储中

时间:2020-05-09 17:45:50

标签: python azure save azure-storage-blobs blobstorage

我正在Azure机器学习平台/云上运行Python代码,但无法弄清楚如何将结果数据帧保存到Azure Blob存储中的csv文件中。有人可以告诉我该怎么做,或指出我可以在其中了解更多信息的地方吗?

1 个答案:

答案 0 :(得分:0)

您是否可以尝试使用以下python代码将文件上传到Azure博客:

global service_client

service_client = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format("https", 'Storage_account_name'), credential='Storage_Account_Key')

#upload file to ADLS Gen 2
file_system_client = service_client.get_file_system_client(file_system="your_container_name")

directory_client = file_system_client.get_directory_client("my-directory")

file_client = directory_client.create_file("uploaded-file.txt")
local_file = open("C:\\Users\\xxxxxxx\\Desktop\\testFile.txt", 'r')

file_contents = local_file.read()

file_client.append_data(data=file_contents, offset=0, length=len(file_contents))

file_client.flush_data(len(file_contents))

有关完整代码的更多详细信息,请访问 this link