繁体   English   中英

从 Azure 存储中获取 blob 时出现问题:Spring 启动

[英]Problem fetching blob from Azure Storage: Spring Boot

我正在构建一个Spring 引导应用程序以从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

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

  • 在这里我有一个解决方法,我们可以手动配置和获取文件,而不是使用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 中的任何内容作为字符串返回在此处输入图像描述

  • 现在关于错误,您正面临错误消息 state 如果在本地运行,请尝试安装 azure cli

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM