如何检查以确保blob_service.put_block_blob_from_path()在python中成功?

时间:2015-09-03 17:32:01

标签: python python-2.7 azure azure-storage-blobs

我必须确保数据已上传。这有更好的方法吗?特别是我想得到一些交易元?

try:
     blob_service.put_block_blob_from_path(
     'user',
     fileName+'.'+ext,
     fileName+'.'+ext)

except:
     print sys.exc_info()[1]

1 个答案:

答案 0 :(得分:3)

Azure SDK for python支持progress_callback方法。我们可以使用回调函数监控进度。

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

def progress_callback(current, total):
    print current
    print "==============="
    print total
    print "==============="
    if(current<total):
        print "unfinish"
    else:
        print "finish"
blob_service = BlobService(account_name=storage_account_name, account_key=storage_account_key)
blob_service.put_block_blob_from_path(container, blob_name, 'C:\\Users\\file_path',progress_callback=progress_callback)

此外,如果您想知道是否在Azure存储上,则可以使用Storage Explore Toollist_blob方法检查文件。 请试一试。

相关问题