This code sample demonstrates how to read and write files with the Spring Resource abstraction for Azure Storage using the Azure Spring Boot Starter Storage. Running this sample will be charged by Azure. You can check the usage and bill at this link.
Maven coordinates:
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>azure-spring-boot-starter-storage</artifactId>
</dependency>
Gradle coordinates:
dependencies {
compile group: 'com.azure.spring', name: 'azure-spring-boot-starter-storage'
}
-
Create Azure Storage
-
Update {application.yml}[application.yml]
# Storage account name length should be between 3 and 24 and use numbers and lower-case letters only # Configuration azure.storage: account-name: [storage-account-name] account-key: [storage-account-access-key] blob-endpoint: [Fill storage Blob service endpoint URL copied from portal] # [Optional] Required if you want to run BlobController file-endpoint: [Fill storage File service endpoint URL copied from portal] # [Optional] Required if you want to run FileController # Resource location, used in this sample resource: blob: [azure-blob://[your-containerName]/[your-blobName]] # [Optional] Required if you want to run BlobController file: [azure-file://[your-fileshareName]/[your-fileName]] # [Optional] Required if you want to run FileController
-
Start the
StorageApplication
Spring Boot app.$ mvn spring-boot:run
-
Send a POST request to update file contents:
$ curl -d 'new message' -H 'Content-Type: text/plain' localhost:8080/blob
Verify by sending a GET request
$ curl -XGET http://localhost:8080/blob
-
Delete the resources on Azure Portal to avoid unexpected charges.
Please check the following table for reference links of detailed Storage usage.
Storage Type | Reference Link |
---|---|
|
https://docs.microsoft.com/azure/storage/storage-java-how-to-use-blob-storage |
|
https://docs.microsoft.com/azure/storage/storage-java-how-to-use-file-storage |
|
https://docs.microsoft.com/azure/storage/storage-java-how-to-use-queue-storage |
|
https://docs.microsoft.com/azure/storage/storage-java-how-to-use-table-storage |