Thursday, February 16, 2017

Azure Blob file download using API in C#

I am working a large Data Integration application and there was a need to share a large file (250+meg ) with vendor who was working on IPad UI application for our sales team. Vendor technology has some limitation to only get the data throug API layer they were adamant to connect to SFtp/DMZ file share etc.

To solve the above business problem we thought we will host the file in AZure Blob and will expose the file using API.

Setting up the Azure Blob to host the File

1. Create a new storage account using portal.azure.com. Make sure to select "General Purpose" option while creating account account. e.g. "apidemostorageaccount"

2. Create a container in the account. eg "ProjectFileContainer"

Code to upload the file to Azure Blob



   Config file
    <add key="StorageConnection" value="DefaultEndpointsProtocol=https;AccountName=??;AccountKey=??" />
    <add key="StorageContainer" value="projectfilecontainer"/>
    <add key="FileName" value="C:\Temp\Launchpad\CustomerMasterData.csv"/>

Code to download the file from Azure Blob


Step 1- Get Sas url


Step -2 GetBlob object url



Step 3 - Return File blob url from web service


Please note the above web service call will return the url of the file. the file url has to be called within 3 minutes to download the file other wise the file url will expire.



1 comment:

Unknown said...

Very informative. Thanks for providing your information. Keep update with us Azure Online Training India