从Azure存储中提取blob时出现问题:Spring Boot

4ngedf3f  于 2023-02-04  发布在  Spring
关注(0)|答案(1)|浏览(618)

我正在构建一个Sping Boot 应用程序,以便从Azure存储上载和检索BLOB数据(图像或文档)。为此,我遵循了此处提供的文档-
https://learn.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-storage
我正在使用VSCode IDE构建和运行项目。当我尝试使用-http://localhost:8080/blob/readBlobFile检索数据时,
我得到以下错误-

[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

我找不到这个问题的原因。有人能帮我找到这个问题吗?

rxztt3cl

rxztt3cl1#

  • 这里我有一个变通方法,我们可以手动配置和提取文件,而不是使用application.yaml连接到Azure Blob存储。
  • 要做到这一点,我们需要一个连接字符串(在门户网站的键选项卡下提供),blob名称,容器名称和端点。
  • 然后我们按照上面的顺序创建blob服务客户端、blob容器客户端和blob客户端。
@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() ;  
  }  
}
  • 在这里,它将以字符串

    的形式返回blob中的任何内容
  • 现在,关于您所面临的错误,错误消息指出,如果在本地运行,请尝试安装Azure CLI

相关问题