How to delete a blob using Azure Functions?(如何使用 Azure Functions 删除 blob?)
问题描述
我正在创建一个 Azure 函数,该函数在图像上传或添加到特定 Azure 存储时触发,它执行以下操作:1.) 调整图像大小2.) 将图像放到正确的目录中(使用输出绑定)3.) 删除处理后添加到 Azure 存储的原始 blob 图像.
I am creating an Azure function that triggers when an image is uploaded or added to a particular Azure Storage, and it does the following: 1.) Resize the image 2.) Put the image to correct directory (using Output binding) 3.) Delete the original blob image that was added to Azure Storage after processing.
我已完成该过程中的步骤 1 和 2,但我发现几乎没有关于删除 Blob 或 API 的文档会公开 Azure 存储的方法.(使用 C#)
I am done with steps 1 and 2 in the process, but I'm finding less to no documentation about deleting a blob or an API that would expose methods for Azure Storage. (Using C#)
示例代码如下:
#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
Name:{imageName}
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
}
推荐答案
要删除一个blob,你需要
To delete a blob, you need to
var container = blobClient.GetContainerReference(containerName);
var blockBlob = container.GetBlockBlobReference(fileName);
return blockBlob.DeleteIfExists();
请确保在尝试此操作之前关闭所有流,以便不再使用该图像.
Make sure that your close all streams before you try this so the image is no longer in use.
这篇关于如何使用 Azure Functions 删除 blob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Azure Functions 删除 blob?


- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01