在 Azure Functions 应用程序 blobtrigger 中设置 blob 的内容类型

Setting the content-type of a blob in Azure functions app blobtrigger(在 Azure Functions 应用程序 blobtrigger 中设置 blob 的内容类型)
本文介绍了在 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 的内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)