Skip to content

Instantly share code, notes, and snippets.

@cmatskas
Created February 7, 2018 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmatskas/6d2f2452361a7b8e54e17def3d4597dc to your computer and use it in GitHub Desktop.
Save cmatskas/6d2f2452361a7b8e54e17def3d4597dc to your computer and use it in GitHub Desktop.
Delete a blob from a queue using a Function
using System;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
namespace SearchFunctions
{
public static class DeleteBlob
{
[FunctionName("DeleteBlob")]
public static async Task Run([QueueTrigger("blobs-to-delete", Connection = "StorageQueueConnectionString")]string myQueueItem,
TraceWriter log)
{
await DeleteBlobByUri(myQueueItem);
log.Info($"C# Queue trigger function processed: {myQueueItem}");
}
private static async Task DeleteBlobByUri(string blobUri)
{
var sa = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("StorageBlobConnectionString"));
var blobClient = sa.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("searchdata");
var blockBlob = new CloudBlockBlob(new Uri(blobUri), sa.Credentials);
await blockBlob.DeleteIfExistsAsync();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment