Downloading files from Microsoft Azure Blob Storage

Home > Microsoft Azure Blob Storage > Example 02

Explanation

This is an example of downloading a file that exists in a specific container in Microsoft Azure Blob Storage. DEXTUploadX5 provides the ability to download files from a container by obtaining a Shared Access Signature (SAS) token. To obtain 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 how to configure DEXTUploadX5 to download files from a container.

// Set up the AZRBS method.
dx.setDownloadMode("AZRBS");
dx.setAZRBSDownloadConfig({
    accountName: "photomanager",
    containerName: "photos",
	// Handler address to generate the shared access token required for each step of the file downloading
    sasDownloadURL: dx5.canonicalize("../service/get-download-sastoken.do")
});

sasDownloadURL is responsible for generating and returning the shared access token required for file downloads. To create a shared access token in the backend, you must use the Azure SDK provided by Microsoft. In a Maven environment, you can obtain the necessary SDK using the following dependency. In the sample project, the necessary JAR files are placed in the WEB-INF/lib folder.

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-storage-blob</artifactId>
    <version>12.31.0</version>
</dependency>

For details on generating a shared access token using the Azure SDK, refer to the AzureSasTokenGenerator and AZRBSDownload classes.

The objects (files) stored in the container can be accessed with the following addressing scheme where ‘key’ is the same as the blob name.

https://{account-name}.blob.core.windows.net/{container-name}/{key}

We recommend that you set the above address to the URL of the virtual file.

dx.addVirtualFile({ name: "bridge_509147.jpg", size: 509147, url: "https://photomanager.blob.core.windows.net/photos/bridge_509147.jpg" });
dx.addVirtualFile({ name: "beach_239826.jpg", size: 239826, url: "https://photomanager.blob.core.windows.net/photos/beach_239826.jpg" });
dx.addVirtualFile({ name: "cosmos (empty) 195779.jpg", size: 195779, url: "https://photomanager.blob.core.windows.net/photos/cosmos+%28empty%29+195779.jpg" });

Example

Single-file download

When the single-file downloading, the destination is not from the same source, so the browser may not download the destination and open it directly.

Multiple-files download