how to transfer file to azure blob storage in chunks without writing to file using python

前端 未结 2 1696
無奈伤痛
無奈伤痛 2021-01-27 00:34

I need to transfer files from google cloud storage to azure blob storage.

Google gives a code snippet to download files to byte variable like so:

# Get P         


        
2条回答
  •  孤独总比滥情好
    2021-01-27 00:59

    After looking through the SDK source code, something like this could work:

    from azure.storage.blob import _chunking
    from azure.storage.blob import BlobService
    
    # See _BlobChunkUploader
    class PartialChunkUploader(_chunking._BlockBlobChunkUploader):
        def __init__(self, blob_service, container_name, blob_name, progress_callback = None):
            super(PartialChunkUploader, self).__init__(blob_service, container_name, blob_name, -1, -1, None, False, 5, 1.0, progress_callback, None)
    
        def process_chunk(self, chunk_offset, chunk_data):
            '''chunk_offset is the integer offset. chunk_data is an array of bytes.'''
            return self._upload_chunk_with_retries(chunk_offset, chunk_data)
    
    blob_service = BlobService(account_name='myaccount', account_key='mykey')
    
    uploader = PartialChunkUploader(blob_service, "container", "foo")
    # while (...):
    #     uploader.process_chunk(...)
    

提交回复
热议问题