How to Upload Images to Microsoft Azure via ASP.NET

The article demonstrates how to upload the document images, scanned by Dynamic Web TWAIN, to Microsoft Azure Web service. You can run the enclosed sample for testing. To learn how to get started with the toolkit, please refer to the Developers’ Guide.

Uploading Images to Azure

Firstly, please create a new web application on the Microsoft Azure. Let’s name it WebTwain.

  1. Click WEB APPS;
  2. Click NEW at the very bottom of the page;
  3. Fill the URL of WebTWAIN.

Then, kindly navigate to the DASHBOARD, and click Download the publish profile.

download profile from azure

Thirdly, please create a storage Dynamsoft. After clicking STORAGE, you will see MANAGE ACCESS KEYS at the very bottom of the page.


manage access key of Azure

Next, please navigate to CONFIGURE > monitoring section, change BLOBS to VERBOSE.

Moreover, in the logging section, check Read, Write and Delete Requests.

Azure configuration

Finally, in CONTAINERS, create a new container with name DWT.

Click Edit, and change the ACCESS to Public Container. Please note the container name is the path in the SAS.aspx.

Azure container

What we need to do is to create an encoded URL from SAS.aspx, and send image data with it via XMLHttpRequest. See how to encode the URL:

<%@Page Language="C#" %>

DateTime utc = DateTime.Now.ToUniversalTime();

// (1) Prepare your data ready
String accountName = "dynamsoft";
String accountKey = "";
String baseUrl = "";
String resourceName = Request["imageName"];
String path = "/dwt";
DateTime utc_start = utc.AddSeconds(-10); 	   		// 10 seconds before
String start = utc_start.GetDateTimeFormats('s')[0].ToString() + ".0000000Z";
DateTime utc_expires = utc.AddSeconds(1200); 		// 20 miniteus later
String expires = utc_expires.GetDateTimeFormats('s')[0].ToString() + ".0000000Z";

// (2) generate signature
String strToSign1 = "w";
String strToSign2 = start;
String strToSign3 = expires;
String strToSign4 = "/" + accountName + path;
String strToSign5 = "";

String strSign = String.Format("{0}\\n{1}\\n{2}\\n{3}\\n{4}", strToSign1, strToSign2, strToSign3, strToSign4, strToSign5);

// decoding
byte[] tobedecodedbytes = System.Convert.FromBase64String(accountKey);

System.Security.Cryptography.HMACSHA256 hmac = new System.Security.Cryptography.HMACSHA256(tobedecodedbytes);
byte[] buffer = Encoding.UTF8.GetBytes(strSign);
byte[] arrMAC =  hmac.ComputeHash(buffer);

String strSig = System.Convert.ToBase64String(arrMAC);

// (3) generate SAS the query 
start = Server.UrlEncode(start);
expires = Server.UrlEncode(expires);
strSig = Server.UrlEncode(strSig);

String strParams = String.Format("sp=w&st={0}&se={1}&sr=c&sig={2}", start, expires, strSig);
String url = baseUrl + resourceName + "?" + strParams;



Source Code

Search Blog Posts