【问题标题】:File storage in azure error handling with python使用 python 处理 azure 错误处理中的文件存储
【发布时间】:2018-06-21 12:32:53
【问题描述】:

我写了一个通用函数来将文件上传到天蓝色存储,但无法弄清楚两件事..

  1. 如何查看上传是否成功
  2. 如何查看进度(天蓝色函数采用布尔参数进度回调,但我不知道如何使用它)

这是我写的函数:

def upload_files_to_azure(share, directory, path_of_file):
"""
Function to upload file to the azure storage, in a particular share into a particular directory
:param share: name of share of azure storage 
:param directory: directory name inside azure storage
:param path_of_file: the path of file to be uploaded 
:return: status of file uploaded 
"""
file_service = FileService(account_name=ACCOUNT_NAME, account_key=ACCOUNT_KEY)
file_service.create_file_from_path(
    share,
    directory,  # We want to create this blob in the root directory, so we specify None for the directory_name
    'test.sql20180103.tar.gz',
    path_of_file,
    content_settings=ContentSettings(content_type='application/x-gzip'))
return

【问题讨论】:

  • 关于#2,你能详细描述一下吗?请分享您遇到的任何文档链接。

标签: python python-3.x azure azure-storage


【解决方案1】:

1.如何判断上传是否成功。

如果您使用的是 Azure Storage SDK,您可以检查是否存在任何异常。如果操作成功,您可以在门户上看到您上传的文件。

如果您使用的是 Azure Storage REST API,您可以查看响应消息和状态码。(200 表示成功)

2.如何查看进度(天蓝色函数采用布尔参数进度回调,但我不知道如何使用它)

我搜索了 Azure Storage Python SDK 并在 create_file_from_path 方法中找到了 progress_callback 参数。

 progress_callback func(current, total) 

您需要知道文件的大小,才能检查操作的进度。你可以从here找到它的用法。

使用签名函数(current, total) 回调进度,其中 current 是到目前为止传输的字节数,total 是文件的大小,如果总大小未知,则为 None。

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    • 1970-01-01
    • 2017-10-26
    • 2011-07-05
    • 2010-11-12
    • 2022-01-05
    • 1970-01-01
    相关资源
    最近更新 更多