Uploading files to Microsoft Azure Blob Storage

Home > Microsoft Azure Blob Storage > Example 01

Explanation

This is an example of uploading a file to a specific container in Microsoft Azure Blob Storage. DEXTUploadX5 provides the ability to upload files to a container by obtaining a Shared Access Signature (SAS) token. To get a shared access token, you need to know the account, container, and access key information in advance, and the access key is sensitive information that should not be exposed to the outside world and must be handled in the backend.

The following code shows the DEXTUploadX5 configuration for uploading files to the container.

// Set up the AZRBS method.			
dx.setUploadMode("AZRBS");
dx.setAZRBSUploadConfig({
    accountName: "photomanager",	
	containerName: "photos",
    // Handler address to generate the shared access token to get a list of uncommitted blocks
    sasListURL: dx5.canonicalize("../service/get-list-sastoken.ashx"),
    // Handler address to generate the shared access token required for each step of the file upload
    sasUploadURL: dx5.canonicalize("../service/get-upload-sastoken.ashx")
});

The sasListURL and sasUploadURL are responsible for generating and returning the shared access token required for each step of the file upload. To create the shared access token on the backend, we need to use the Azure SDK provided by Microsoft, which can be installed via NuGet for ASP.NET. In our sample project, we put the required Azure SDK binary files in the packages folder. Refer to the two generic handler codes for the details of generating a shared access token using the Azure SDK.

The container in Azure Blob Storage also needs to be set up for uploading. In Azure Home, select your storage account and you'll find the Resource Sharing (CORS) settings menu. On the Blob Service tab, allow the GET, HEAD, POST, OPTIONS, and PUT methods, and set content-type, x-requested-with, and x-ms-* in the request header.

Example

Result