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.do"),
// Handler address to generate the shared access token required for each step of the file upload
sasUploadURL: dx5.canonicalize("../service/get-upload-sastoken.do")
});
sasListURL and sasUploadURL are responsible for generating and returning shared access tokens required for each step of file upload. To create shared access tokens in the backend, you need to use the Azure SDK provided by Microsoft. In a Maven environment, you can obtain the necessary SDK using the following dependencies. 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 shared access tokens using the Azure SDK, refer to the AzureSasTokenGenerator, AZRBSList, and AZRBSUpload classes.
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
|
|