javaspring-bootazure-storagecredentialsblobstorage

Problem fetching blob from Azure Storage: Spring Boot


I am building a Spring Boot Application to upload and retrieve BLOB data (images or documents) from the Azure Storage. For the purpose I followed the documentation given here-
https://learn.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-storage

I am using VSCode IDE for building and running the project. When I try to retrieve the data using- http://localhost:8080/blob/readBlobFile,
I get the following error-

[Request processing failed: com.azure.identity.CredentialUnavailableException: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/environmentcredential/troubleshoot
Managed Identity authentication is not available.
SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.
IntelliJ Authentication not available. Please log in with Azure Tools for IntelliJ plugin in the IDE.
AzureCliCredential authentication unavailable. Azure CLI not installed.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/azclicredential/troubleshoot
Azure PowerShell authentication failed using defaultpowershell(pwsh) with following error: Unable to execute PowerShell. Please make sure that it is installed in your system.
Azure PowerShell authentication failed using powershell-core(powershell) with following error: Az.Account module with version >= 2.2.0 is not installed. It needs to be installed to use Azure PowerShell Credential.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azure-identity-java-default-azure-credential-troubleshoot] with root cause

com.azure.identity.CredentialUnavailableException: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/environmentcredential/troubleshoot
Managed Identity authentication is not available.
SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.
IntelliJ Authentication not available. Please log in with Azure Tools for IntelliJ plugin in the IDE.
AzureCliCredential authentication unavailable. Azure CLI not installed.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/azclicredential/troubleshoot
Azure PowerShell authentication failed using defaultpowershell(pwsh) with following error: Unable to execute PowerShell. Please make sure that it is installed in your system.
Azure PowerShell authentication failed using powershell-core(powershell) with following error: Az.Account module with version >= 2.2.0 is not installed. It needs to be installed to use Azure PowerShell Credential.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azure-identity-java-default-azure-credential-troubleshoot

I am not able to find the reason for this problem. Can somebody help me find the issue?


Solution

  • @RestController  
    @RequestMapping("blob")  
    public class BlobController {  
        private String enpoint = "https://<Storage Account Name>.blob.core.windows.net/";  
     private String connectionString = "";  
     private String containerName = "test" ;   
     private String blobName = "document.txt" ;  
      
      @GetMapping("/readBlobFile")  
        public String readBlobFile () throws IOException  
        {  
            BlobServiceClient blobServiceClient =  new BlobServiceClientBuilder()  
                    .endpoint(enpoint)  
                    .connectionString(connectionString)  
                    .buildClient();  
      BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient(containerName);  
      BlobClient blobClient = containerClient.getBlobClient(blobName);  
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();  
      blobClient.downloadStream(outputStream);  
      
     return outputStream.toString() ;  
      }  
    }