Überprüfen, ob in Python Azure ein Blob vorhanden ist

Sep 15 2020

Seit dem neuen Update von azure-storage-blob wird der blockblobservice abgeschrieben

Wie kann ich überprüfen, ob ein Blob vorhanden ist?

Diese Antwort funktioniert nicht mit der neuen Version von Azure -Storage-Blob. Schnellere Azure-Blob-Namenssuche mit Python?

Ich habe dieses Problem auf GitHub gefunden: https://github.com/Azure/azure-sdk-for-python/issues/12744

Antworten

4 krishg Sep 15 2020 at 04:11

Die am 10.09.2020 veröffentlichte Version 12.5.0 enthält jetzt die existsMethode im neuen SDK.

Zum Beispiel,

Synchronisieren:

from azure.storage.blob import BlobClient

blob = BlobClient.from_connection_string(conn_str="my_connection_string", container_name="mycontainer", blob_name="myblob")
exists = blob.exists()
print(exists)

Async:

import asyncio

async def check():
    from azure.storage.blob.aio import BlobClient
    blob = BlobClient.from_connection_string(conn_str="my_connection_string", container_name="mycontainer", blob_name="myblob")
    async with blob:
        exists = await blob.exists()
        print(exists)