在Azure函数应用程序blobtrigger中设置Blob的内容类型 [英] Setting the content-type of a blob in Azure functions app blobtrigger
问题描述
我正在尝试调整上传到我的容器中的图片的大小,以便为我的网站创建缩略图和其他各种版本的图片.
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\n Name:{blobname} \n 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\n Name:{blobname} \n 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);
}
推荐答案
使用流输出时,函数会将您的内容类型默认为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函数应用程序blobtrigger中设置Blob的内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!