Open an Azure StorageStreamDownloader without saving it as a file

后端 未结 2 884
孤独总比滥情好
孤独总比滥情好 2021-01-16 06:44

I need to download a PDF from a blob container in azure as a download stream (StorageStreamDownloader) and open it in both PDFPlumber and PDFminer. I developed all the requi

2条回答
  •  爱一瞬间的悲伤
    2021-01-16 07:24

    It seems download_to_stream() is now deprecated and instead should be used readinto().

    from azure.storage.blob import BlobClient
    
    
    conn_string = ''
    container_name = ''
    blob_name = ''
    blob_obj = BlobClient.from_connection_string(
        conn_str=conn_string, container_name=container_name,
        blob_name=blob_name
    )
    with open(blob_name, 'wb') as f:
        b = blob_obj.download_blob()
        b.readinto(f)
    

    This will create a file in working directory with the data that was downloaded.

提交回复
热议问题