Setting the content-type of a blob in Azure functions app blobtrigger(在 Azure Functions 应用程序 blobtrigger 中设置 blob 的内容类型)
问题描述
我正在尝试调整上传到我的容器的图像的大小,以便为我的网站创建缩略图和其他各种版本的图像.
I am trying to resize the images uploaded to my container in order to create thumbnails and various other versions of my images for my site.
我上传的图片必须更正内容类型image/jpeg";但是当我使用下面的代码创建它们的新版本时,结果显示为application/octet-stream".
The images I upload have to correct content-type "image/jpeg" but when I create a new version of them using the code below it turns out as "application/octet-stream".
我在这里错过了什么?
using ImageResizer;
using ImageResizer.ExtensionMethods;
public static void Run(Stream myBlob, string blobname, string blobextension, Stream outputBlob, TraceWriter log)
{
log.Info($"C# Blob trigger function Processed blob
Name:{blobname}
Size: {myBlob.Length} Bytes");
var instructions = new Instructions
{
Width = 570,
Mode = FitMode.Crop,
Scale = ScaleMode.Both,
};
ImageBuilder.Current.Build(new ImageJob(myBlob, outputBlob, instructions));
}
解决方案.
#r "Microsoft.WindowsAzure.Storage"
using ImageResizer;
using ImageResizer.ExtensionMethods;
using Microsoft.WindowsAzure.Storage.Blob;
public static void Run(Stream myBlob, string blobname, string blobextension, CloudBlockBlob outputBlob, TraceWriter log)
{
log.Info($"C# Blob trigger function Processed blob
Name:{blobname}
Size: {myBlob.Length} Bytes");
var instructions = new Instructions
{
Width = 570,
Mode = FitMode.Crop,
Scale = ScaleMode.Both
};
Stream stream = new MemoryStream();
ImageBuilder.Current.Build(new ImageJob(myBlob, stream, instructions));
stream.Seek(0, SeekOrigin.Begin);
outputBlob.Properties.ContentType = "image/jpeg";
outputBlob.UploadFromStream(stream);
}
推荐答案
当你使用流输出时,函数会默认你的 content-type 为 application/octet-stream.
When you use the stream output, functions will default your content-type to application/octet-stream.
使用其中一种 ICloudBlob 类型,它应该允许您指定 blob 的内容类型.
Use one of the ICloudBlob types, which should allow you to specify the content type of your blob.
以下是可以作为参数绑定的类型的备忘单:https://jhaleyfiles2016.blob.core.windows.net/public/Azure%20WebJobs%20SDK%20Cheat%20Sheet%202014.pdf
Here's a cheatsheet of types you can bind to as parameters: https://jhaleyfiles2016.blob.core.windows.net/public/Azure%20WebJobs%20SDK%20Cheat%20Sheet%202014.pdf
这篇关于在 Azure Functions 应用程序 blobtrigger 中设置 blob 的内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Azure Functions 应用程序 blobtrigger 中设置 blob 的内容类型
基础教程推荐
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- SSE 浮点算术是否可重现? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01