Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUERY] Is it possible to delete a Blob through a BlobItem? #20092

Closed
WillRock19 opened this issue Apr 5, 2021 · 2 comments
Closed

[QUERY] Is it possible to delete a Blob through a BlobItem? #20092

WillRock19 opened this issue Apr 5, 2021 · 2 comments
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)

Comments

@WillRock19
Copy link

Query/Question
I'm converting a logic from an old library to a new one. In here, I'm getting all blobs from a container, filtering it by the LastModified property, and then deleting it. With the old library, I could do this in a very straight foward manner:

        var storageConnectionString = ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ConnectionString;
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);
	CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

	var containerHostArchive = blobClient.GetContainerReference("azure-jobs-host-archive");
	if (containerHostArchive.Exists())
	{
		var blobsHostArchive = containerHostArchive
			.ListBlobs()
			.OfType<CloudBlob>()
			.Where(b => b.Properties.LastModified < new DateTimeOffset(DateTime.Now.AddDays(-RETENTION_DAYS_JOBS_LOGS)))
			.ToList();

		foreach (var item in blobsHostArchive)
		{
			item.DeleteIfExists();
		}
	}

In the new library, I'm not finding a easy way to do this. I have to make two access to the storage, first one to find the BlobItems from a container, the second to get a reference to the BlobClient so I can delete it (see bellow):}

                var blobContainerClient = storageWrapper.GetContainerReference(_connectionString, containerName); //Returns a BlobContainerClient
                var dateLastWeek = DateTime.Now.AddDays(-7);

                var desiredBlobs = blobContainerClient
                    .GetBlobs()
                    .ToList()
                    .Where(x => x.Properties.LastModified < dateLastWeek)
                    .ToList();

                var blobsToDelete = desiredBlobs
                    .Select(blob => storageWrapper.GetBlobReferenceNew(_connectionString, containerName, blob.Name)) //GetReferenceNew returns a BlobClient
                    .ToList();

                blobsToDelete.ForEach(blob => blob.DeleteIfExists());

Is there a way to do this without accessing the storage twice?

Environment:

  • .Net Version: Full Framework 4.8
  • Original version: Microsoft.WindowsAzure.Storage.Blob 9.3.2.0
  • New version: Azure.Storage.Blobs v12.8.0
  • IDE and version : Visual Studio 16.8.5
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Apr 5, 2021
@jsquire jsquire added Client This issue points to a problem in the data-plane of the library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files) labels Apr 5, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Apr 5, 2021
@ghost
Copy link

ghost commented Apr 5, 2021

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

Issue Details

Query/Question
I'm converting a logic from an old library to a new one. In here, I'm getting all blobs from a container, filtering it by the LastModified property, and then deleting it. With the old library, I could do this in a very straight foward manner:

        var storageConnectionString = ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ConnectionString;
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);
	CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

	var containerHostArchive = blobClient.GetContainerReference("azure-jobs-host-archive");
	if (containerHostArchive.Exists())
	{
		var blobsHostArchive = containerHostArchive
			.ListBlobs()
			.OfType<CloudBlob>()
			.Where(b => b.Properties.LastModified < new DateTimeOffset(DateTime.Now.AddDays(-RETENTION_DAYS_JOBS_LOGS)))
			.ToList();

		foreach (var item in blobsHostArchive)
		{
			item.DeleteIfExists();
		}
	}

In the new library, I'm not finding a easy way to do this. I have to make two access to the storage, first one to find the BlobItems from a container, the second to get a reference to the BlobClient so I can delete it (see bellow):}

                var blobContainerClient = storageWrapper.GetContainerReference(_connectionString, containerName); //Returns a BlobContainerClient
                var dateLastWeek = DateTime.Now.AddDays(-7);

                var desiredBlobs = blobContainerClient
                    .GetBlobs()
                    .ToList()
                    .Where(x => x.Properties.LastModified < dateLastWeek)
                    .ToList();

                var blobsToDelete = desiredBlobs
                    .Select(blob => storageWrapper.GetBlobReferenceNew(_connectionString, containerName, blob.Name)) //GetReferenceNew returns a BlobClient
                    .ToList();

                blobsToDelete.ForEach(blob => blob.DeleteIfExists());

Is there a way to do this without accessing the storage twice?

Environment:

  • .Net Version: Full Framework 4.8
  • Original version: Microsoft.WindowsAzure.Storage.Blob 9.3.2.0
  • New version: Azure.Storage.Blobs v12.8.0
  • IDE and version : Visual Studio 16.8.5
Author: WillRock19
Assignees: -
Labels:

Client, Service Attention, Storage, customer-reported, needs-team-attention, needs-triage, question

Milestone: -

@seanmcc-msft
Copy link
Member

This functionality is not supported by the SDK. BlobItem is a model, BlobClient is a client. This is a well established pattern in the new SDKs across Azure.

I have to make two access to the storage, first one to find the BlobItems from a container, the second to get a reference to the BlobClient so I can delete it

Getting a refence to a BlobClient doesn't actually make a REST call into the service, it just creates a new BlobClient locally. Same for newing up a BlobContainerClient

No matter what the SDK APIs look like, there is going to be a call into the storage service to list the blobs in a container, and another call for each blob you would like to delete.

-Sean

azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Aug 5, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

No branches or pull requests

3 participants