This code sample demonstrates how to read and write files with the Spring Resource abstraction for Azure Storage using the Spring Cloud Azure Storage Starter. 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>spring-cloud-azure-starter-storage-file-share</artifactId>
</dependency>
Gradle coordinates:
dependencies {
compile group: 'com.azure.spring', name: 'spring-cloud-azure-starter-storage-file-share'
}
-
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 spring: cloud: azure: storage: fileshare: account-name: [storage-account-name] account-key: [storage-account-access-key] 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: file: [azure-file://[your-fileshareName]/[your-fileName]] # [Optional] Required if you want to run FileController
-
Start the
StorageFileShareApplication
Spring Boot app.mvn spring-boot:run
-
Send a POST request to update file contents:
curl -d 'new message' -H 'Content-Type: text/plain' http://localhost:8080/file
Verify by sending a GET request
curl -XGET http://localhost:8080/file
Verify in app’s log the messages was posted:
new message
-
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 |