-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Comments
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage. Issue DetailsQuery/Question 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:
|
This functionality is not supported by the SDK.
Getting a refence to a 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 |
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
migrate to .net track 2 batch 2 (Azure#20092)
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:
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):}
Is there a way to do this without accessing the storage twice?
Environment:
The text was updated successfully, but these errors were encountered: