【发布时间】:2017-10-12 06:03:27
【问题描述】:
我正在尝试调整上传到我的容器的图像的大小,以便为我的网站创建缩略图和其他各种版本的图像。
我上传的图片必须更正内容类型“image/jpeg”,但是当我使用下面的代码创建它们的新版本时,结果显示为“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);
}
【问题讨论】:
标签: c# azure azure-blob-storage image-resizing azure-functions