azure中的文件存储使用python进行错误处理
我编写了一个genecric函数来将文件上传到azure存储中,但无法理解两件事azure中的文件存储使用python进行错误处理,python,python-3.x,azure,azure-storage,Python,Python 3.x,Azure,Azure Storage,我编写了一个genecric函数来将文件上传到azure存储中,但无法理解两件事 如何检查上传是否成功 如何检查进度(azure函数接受一个布尔参数progress回调,但我不知道如何使用它) 以下是我编写的函数: def upload_files_to_azure(share, directory, path_of_file): """ Function to upload file to the azure storage, in a particular share into a part
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
1.如何检查上传是否成功
如果您使用的是Azure Storage SDK,则可以检查是否存在任何异常。如果操作成功,您可以在门户上看到上载的文件
如果您使用的是Azure Storage REST API,则可以检查响应消息和状态代码。(200表示成功)
2.如何检查进度(azure函数接受一个布尔参数progress callback,但我不知道如何使用它)
我搜索了Azure Storage Python SDK,并在create\u file\u from\u path
方法中找到了progress\u回调
参数
progress_callback func(current, total)
您需要知道文件的大小,这样才能检查操作的进度。你可以从中找到它的用法
使用签名函数(current,total)回调进度,其中current是到目前为止传输的字节数,total是文件的大小,如果总大小未知,则为None
希望能对您有所帮助。关于#2,您能详细描述一下吗?请分享您遇到的任何文档链接。