c# - 如何在 Azure 函数中设置 blob 属性?
问题描述
此示例说明如何设置 blob 属性,例如ContentType
使用 C#。如何在以下 Azure 函数中完成此操作?方法签名不使用CloudBlob
对象,而是使用Stream
对象来读取 blob。
[FunctionName("MyFunction")]
public static async Task Run([BlobTrigger("container-name/folder-name/{name}", Connection = "ConnectionString")]Stream myBlob, string name, ILogger log, Binder binder)
{
// How to change the ContentType property?
}
解决方案
请使用以下代码(我使用的是 Visual Studio 2017,并创建函数 v2):
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Blob;
namespace FunctionApp3
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([BlobTrigger("container-name/folder-name/{name}", Connection = "AzureWebJobsStorage")]ICloudBlob myBlob, string name, ILogger log)
{
log.LogInformation("...change blob property...");
//specify the property here
myBlob.Properties.ContentType = "text/html";
//commit the property
myBlob.SetPropertiesAsync();
}
}
}
推荐阅读
- swift - UIStackView - 为什么堆栈位于另一个之上?
- xml - 如何使用带有自定义行名的 XSLT 填充表
- javascript - 试图阻止标准的右键菜单
- python - 如何将非 Tensorflow 代码与 Tensorflow 操作混合使用?
- android - 如何在 Cloud Firestore 上添加、更新、删除和读取?
- laravel-nova - 全新 Nova 安装,但无法删除新创建的用户
- python - 如何使用正则表达式只保留前 n 个重复的单词
- node.js - 在 Linux 机器上部署 node.js/express 服务器需要哪些监控工具?
- powershell - 创建将计算机移动到 AD OU 并从 CSV 文件中从 SCCM 中删除它们的脚本
- c++ - 在模板参数中使用 ref<>?