Created
February 7, 2018 15:47
-
-
Save cmatskas/6d2f2452361a7b8e54e17def3d4597dc to your computer and use it in GitHub Desktop.
Delete a blob from a queue using a Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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