azure-functions - 如何更改输出 Blob 流的内容类型?
问题描述
我有一个函数可以获取一个 blob,调整它的大小并将其输出到另一个容器。
public static void Run(
[BlobTrigger("test/{name}")] Stream image,
string name,
[Blob("test-tn/{name}", FileAccess.Write)] Stream imageSmall, ILogger log)
然而,生成的图像将始终具有流的内容类型,我想定义内容类型。
我假设我可以输出 CloudBlockBlob 而不是流,但我总是收到此错误:
Can't bind Blob to type 'Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob
为 BlobTrigger 的输出定义内容类型的最佳方法是什么?
解决方案
我认为您问题的根源在于您使用的是过时版本的 Storage nuget 包。有关Blob 输出的完整示例,请参见此处:
.csproj
文件片段:
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="4.0.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.3" />
Http2BlobFunction.cs
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Azure.Storage.Blob;
namespace SampleFunctions
{
public static class Http2BlobFunction
{
[FunctionName(nameof(Http2Blob))]
public static async Task<IActionResult> Http2Blob(
[HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequest req,
[Blob("myblobcontainer/{rand-guid}.txt", FileAccess.ReadWrite)] CloudBlockBlob blob,
ILogger log)
{
log.LogInformation("Received file upload request");
var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
await blob.UploadTextAsync(requestBody);
return new OkObjectResult(blob.Name);
}
}
}
推荐阅读
- spring - spring cloud zuul "path": "/actuator/routes" 404 not found
- php - 如何在 Laravel 中配置 API 密钥和 API 机密?
- css - 仅选择嵌套循环中的前 3 个子 div
- gcc - C 交叉编译器中的分段内存模型
- angularjs - 如何让restangular customGET获取第二个参数?
- javascript - Firebase NPM 包中缺少区域
- python - 读取整个文件并将其存储在列表中而不会丢失内容拆分它
- javascript - 在 Firestore 中进行动态过滤是否有更优化的方法?
- angular - 设置 nativescript-purchase 组件
- google-app-engine - 如何在标准环境中使用 Appengine Gradle 插件