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

前端 未结 2 1695
無奈伤痛
無奈伤痛 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

    According to the source codes of blobservice.py for Azure Storage and BlobReader for Google Cloud Storage, you can try to use the Azure function blobservice.put_block_blob_from_file to write the stream from the GCS class blobreader has the function read as stream, please see below.

    So refering to the code from https://cloud.google.com/appengine/docs/python/blobstore/#Python_Using_BlobReader, you can try to do this as below.

    from google.appengine.ext import blobstore
    from azure.storage.blob import BlobService
    
    blob_key = ...
    blob_reader = blobstore.BlobReader(blob_key)
    
    blob_service = BlobService(account_name, account_key)
    container_name = ...
    blob_name = ...
    blobservice.put_block_blob_from_file(container_name, blob_name, blob_reader)
    

提交回复
热议问题