简体   繁体   English

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

[英]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 .我正在构建一个Spring 引导应用程序以从Azure 存储上传和检索BLOB 数据(图像或文档)。 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 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.我正在使用 VSCode IDE 来构建和运行项目。 When I try to retrieve the data using- http://localhost:8080/blob/readBlobFile,当我尝试使用 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?有人可以帮我找到问题吗?

  • Here I have a work around where Instead of using the application.yaml to connect to azure blob storage we can manually configure and fetch the file.在这里我有一个解决方法,我们可以手动配置和获取文件,而不是使用application.yaml连接到 azure blob 存储。

  • To do this we would need a connection string (available in portal under keys tab), blob name, container name and endpoint.为此,我们需要一个连接字符串(在门户中的密钥选项卡下可用)、blob 名称、容器名称和端点。

  • Then we create a blob service client, a blob container client and a blob client in the exact order as above.然后我们按照上面的确切顺序创建一个 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() ;  
  }  
}
  • Here it would return anything in the blob as a string在这里它会将 blob 中的任何内容作为字符串返回在此处输入图像描述

  • Now regarding the error, you are facing, as the error message state try installing the azure cli if running locally现在关于错误,您正面临错误消息 state 如果在本地运行,请尝试安装 azure cli

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

相关问题 无法从 Azure Blob 存储检索图像 - Could not retrieve image from Azure Blob Storage 如何从 azure blob 存储中读取“.owl” - How to read an ".owl" from azure blob storage 文件从 DBFS 传输到 Azure Blob 存储 - file transfer from DBFS to Azure Blob Storage 从 azure blob 存储中获取文件名 - Get file names from azure blob storage 将文件从 Azure blob 存储移动到 Google 云存储桶 - Moving Files from Azure blob storage to Google cloud storage bucket 从 azure blob 存储(静态网站)访问 azure 密钥库 - Access azure key vault from azure blob storage (static website) 将最新的文件夹从 azure blob 存储加载到 azure 数据工厂 - Load the latest folder from azure blob storage to azure data factory 包括Azure Blob存储库导致Spring出现问题 - Including Azure Blob storage library causes problems in Spring 来自 PUT 的 Azure Blob 存储文档中的“404 Resource Not Found” - "404 Resource Not Found" From Azure Blob Storage Document from PUT 通过 URL 从 Spring 应用程序访问 Azure bolb 存储中的图像时出现问题 - Problem accesing image in Azure bolb storage from Spring app via URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM