How can I get references to BlockBlob objects from CloudBlobDirectory.ListBlobs?

后端 未结 3 2186
长发绾君心
长发绾君心 2021-02-07 02:53

I am using the Microsoft Azure .NET client libraries to interact with Azure cloud storage. I need to be able to access additional information about each blob in its metadata col

3条回答
  •  故里飘歌
    2021-02-07 03:36

    This approach has been developed for Java, but I hope it can somehow be modified to fit any other supported language. Despite the functionality you ask has not been explicitly developed yet, I think I found a different (hopefully less clunky) way to access CloudBlockBlob data from a ListBlobItem element.

    The following code can be used to delete, for example, every blob inside a specific directory.

    String blobUri;
    CloudBlobClient blobClient = /* Obtain your blob client */
    
    try{
         CloudBlobContainer container = /* Obtain your blob container */
    
         for (ListBlobItem blobItem : container.listBlobs(blobPrefix)) {
    
              if (blobItem instanceof CloudBlob) {
                    blob = (CloudBlob) blobItem;
                    if (blob.exists()){
                        System.out.println("Deleting blob " + blob.getName());
                        blob.delete();
                    }
              }
         }
    }catch (URISyntaxException | StorageException ex){
            Logger.getLogger(BlobOperations.class.getName()).log(Level.SEVERE, null, ex);
    }
    

提交回复
热议问题