Setting the content-type of a blob in Azure functions app blobtrigger

azure, azure-blob-storage, azure-functions, c#, image-resizing

Solution

When you use the stream output, functions will default your content-type to application/octet-stream.

Use one of the ICloudBlob types, which should allow you to specify the content type of your blob.

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

Problem

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. 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". What am I missing here? ``` 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)); } ``` Edit: The solution. ``` #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); } ```

Original source