[英]File storage in azure error handling with python
我編寫了一個泛型函數來將文件上傳到azure存儲中,但無法弄清楚兩件事。
這是我寫的函數:
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函數采用布爾型參數進度回調,但我不知道如何使用它)
我搜索了Azure存儲Python SDK,並在create_file_from_path
方法中找到了progress_callback
參數。
progress_callback func(current, total)
您需要知道文件的大小 ,然后才能檢查操作的進度。 您可以從這里找到它的用法。
使用簽名函數(當前,總計)進行進度回調,其中current是到目前為止已傳輸的字節數,total是文件的大小,如果總大小未知,則為None。
希望對您有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.