Uploading an image to a Blob Container via Web API

If you're looking for help with C#, .NET, Azure, Architecture, or would simply value an independent opinion then please get in touch here or over on Twitter.

Handling image (or other binary object) uploads via Web API for storing in Azure blob storage without using the local file system (handy if, for example, you’re using Azure Websites) seems to be a frequently asked question.

I’ve not tested this in anger yet but I’ve posted my own attempt at solving this issue as a gist on GitHub and shown below. It seems to work but as I say I’ve not tested it in anger, only in fairly limited scenarios.

If you use my Azure Application Framework I’ve also added a GetMultipartStreamProvider method to the IAsynchronousBlockBlobRepository interface that provides a pre-configured implementation for a given blob container.

Hope thats helpful.

5 thoughts on “Uploading an image to a Blob Container via Web API

  1. Hello,
    Thx for this just what I needed! I’m having difficulty renaming the file before it’s saved to the store. I’ve tried modifying the incoming request header in the ImageUploadController without success. Any suggestions?

    Thx!

    1. Hi Sam,

      The trick is to modify it in the MultipartStreamProvider. I have a more recent version of the BlobStorageMultipartStreamProvider class in my application support library that allows a filename to be set. During the getting of the stream it passes the content disposition header to an action / delegate – that action / delegate can set any filename it likes, this can be completely new or based on the filename that was uploaded.

      It’s in Git here.

      Hope that helps.

  2. hello. this is very helpful and works fine if i’m uploading from my local server. well i try to use when uploading from mobile(android).As a server side the web api is working fine, but seems that I’m having difficulty explaining to the mobile part what data to send me , because whenever they try to access the web api it returns a “unsupported media type” error.so I was wondering how can I vew the request content from my side so that I can track what am I receiving.Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact

  • If you're looking for help with C#, .NET, Azure, Architecture, or would simply value an independent opinion then please get in touch here or over on Twitter.

Recent Posts

Recent Tweets

Invalid or expired token.

Recent Comments

Archives

Categories

Meta

GiottoPress by Enrique Chavez