I'm creating an Azure Function that is bound to my Azure Blob Storage container and triggers whenever a file is uploaded.
This particular container could have any type of file/blob in it e.g. image, PDF, Excel, MP4, etc.
I want to create different handlers that will do something depending on uploaded file type. For example, if it's an image file, I want to get its dimensions. If it's an MP4, I want to call another service to process the video, etc.
How do I get the file type from Stream
? It's important to note that I cannot rely on file extension as in some cases, the extension may not be there. Is there a way for me to get the mimetype
?
This is the standard BlogTrigger
Azure Function code:
[FunctionName("FileManager")]
public static void Run([BlobTrigger("my-container/{name}", Connection = "myConnectionString")]Stream myBlob, string name, ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
}
You can get these properties.
The Content-Type (if set when uploaded) is returned in
metaData
argument.