Vérifier si un objet blob existe dans python azure

Sep 15 2020

Depuis la nouvelle mise à jour de azure-storage-blob, le blockblobservice est déprécié

Comment puis-je vérifier qu'un blob existe?

Cette réponse ne fonctionne pas avec la nouvelle version d' Azure -storage-blob Recherche plus rapide de noms d'objets blob Azure avec python?

J'ai trouvé ce problème sur GitHub: https://github.com/Azure/azure-sdk-for-python/issues/12744

Réponses

4 krishg Sep 15 2020 at 04:11

La version 12.5.0 publiée le 10/09/2020 a maintenant la existsméthode dans le nouveau SDK.

Par exemple,

Synchroniser:

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)