How to remove blob using Azure functions?

I create an Azure function that runs when an image is uploaded or added to a specific Azure storage, and it does the following: 1.) Resize the image 2.) Put the image in the correct directory (using output binding) 3.) Delete the original drop image that was added to the Azure repository after processing.

In this process, everything is done with steps 1 and 2, but I do not see any documentation about removing blob or APIs that will expose methods for Azure Storage. (Using C #)

Here is an example code:

#r "System.Drawing"
using System;
using ImageResizer;
using System.Drawing;
using System.Drawing.Imaging;

public static void Run(Stream inputImage, string imageName, Stream resizedImage, TraceWriter log)
{
    // Log the file name and size
    log.Info($"C# Blob trigger function Processed blob\n Name:{imageName} \n Size: {inputImage.Length} Bytes");

    // Manipulate the image
    var settings = new ImageResizer.ResizeSettings
    {
        MaxWidth = 400,
        Format = "png"
    };

    ImageResizer.ImageBuilder.Current.Build(inputImage, resizedImage, settings);

    // Delete the Raw Original Image Step
}
+4
source share
3 answers

To remove blob you need

var container = blobClient.GetContainerReference(containerName);
var blockBlob = container.GetBlockBlobReference(fileName);
return blockBlob.DeleteIfExists();

, , , , .

+5

:

#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage.Blob;

CloudBlockBlob :

public static void Run(CloudBlockBlob myBlob, string name, TraceWriter log)
{
    myBlob.DeleteIfExists();
}
+3

, #, webjobs sdk .

In your case, you can request your input image as CloudBlockBlobone that has a delete method. You can call this inside the resize function or in a separately run function to remove completed drops. You may need to change the binding directionto inout, see here .

There is currently no need to link automatic cleaning.

0
source

Source: https://habr.com/ru/post/1669232/


All Articles