java理解Azure文件存储:未知hostException
编辑:我刚刚意识到下面的AccountName指的是一个我尚未创建的存储帐户。我以为这只是我拥有的一般azure“帐户”。令人失望
我正在研究thisJava/Azure文件存储示例。我遇到了一个问题,我无法找到解决方案:
英文:https://docs.microsoft.com/en-us/azure/storage/files/storage-java-how-to-use-file-storage?tabs=java
createFileShare异常:java。网UnknownHostException:未能解析“我提供的帐户名”。文件果心窗户。net在2次查询后返回
我不确定AccountName和AccountKey的确切定义,我认为这是正确的
我的目标代码:
public static final String connectStr =
"DefaultEndpointsProtocol=https;" +
"AccountName=my-provided-accountname;" +
"AccountKey=87D2A2E999180C4A624E1A8153CEBD6";
public static void main(String[] args) {
SpringApplication.run(AzureFileStorageApplication.class, args);
ShareClient shareClient = new ShareClientBuilder()
.connectionString(connectStr).shareName("testfilestorage")
.buildClient();
createFileShare(connectStr,"hello1A");
}
public static Boolean createFileShare(String connectStr, String shareName)
{
try
{
ShareClient shareClient = new ShareClientBuilder()
.connectionString(connectStr).shareName(shareName)
.buildClient();
shareClient.create();
System.out.println(shareClient);
return true;
}
catch (Exception e)
{
System.out.println("createFileShare exception: " + e.getMessage());
return false;
}
}
# 1 楼答案
结果是Azure不喜欢我用作文件名的camelCase。将其更改为以下操作:
# 2 楼答案
首先,您应该创建一个Azure存储帐户 https://docs.microsoft.com/en-us/azure/storage/common/storage-account-create?tabs=azure-portal
并将其粘贴到代码中。例如:
创建Azure存储帐户时,获取AccountKey(如下面链接中所述)
https://docs.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage?tabs=azure-portal
并将其粘贴到代码中。例如:
Java ShareClientBuilder文档描述了使用连接字符串实例化共享客户端。 https://docs.microsoft.com/en-us/java/api/com.azure.storage.file.share.shareclientbuilder?view=azure-java-stable
在您的情况下,您应该附加“EndpointSuffix=core.windows.net”连接到您的connectStr