【问题标题】:understanding Azure File Storage: UnknownHostException了解 Azure 文件存储:UnknownHostException
【发布时间】:2021-01-14 18:57:37
【问题描述】:

编辑:我刚刚意识到下面的 AccountName 指的是我尚未创建的存储帐户。我认为这只是我拥有的一般天蓝色“帐户”。令人失望。

我正在处理this Java/Azure 文件存储示例。我遇到了一个问题,我无法找到解决方案:

英文:https://docs.microsoft.com/en-us/azure/storage/files/storage-java-how-to-use-file-storage?tabs=java

createFileShare 异常:java.net.UnknownHostException:2 次查询后无法解析“my-provided-accountname.file.core.windows.net”

我不确定究竟为 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;
    }
}

【问题讨论】:

  • 你有那个教程的英文链接吗?
  • 我提供了一个链接,也许教程这个词太强了。点击上方的“这个”。
  • 我在德国,chrome 会自动将我带到英语。
  • 我实际上没有使用过 Azure 文件存储,但我希望 URL 是 https://<name>.file.core.windows.net/,而不仅仅是 <name>.core

标签: java azure


【解决方案1】:

首先您应该创建一个 Azure 存储帐户 https://docs.microsoft.com/en-us/azure/storage/common/storage-account-create?tabs=azure-portal

并将其粘贴到代码中。示例:

AccountName=myazurestorageaccount;

创建 Azure 存储帐户后,获取 AccountKey(如下链接所述)

https://docs.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage?tabs=azure-portal

并将其粘贴到代码中。示例:

AccountKey=87D2A2E999180C4A624E1A8153CEBD6;

Java ShareClientBuilder 文档描述了使用连接字符串实例化共享客户端。 https://docs.microsoft.com/en-us/java/api/com.azure.storage.file.share.shareclientbuilder?view=azure-java-stable

String connectionString = "DefaultEndpointsProtocol=https;AccountName={name};AccountKey={key};"
 + "EndpointSuffix={core.windows.net}";
ShareClient shareClient = new ShareClientBuilder()
 .connectionString(connectionString).shareName("myshare")
 .buildClient();

在您的情况下,您应该将 "EndpointSuffix=core.windows.net"; 附加到您的 connectStr。

public static final String connectStr = 
    "DefaultEndpointsProtocol=https;" +
            "AccountName=my-provided-accountname;" +
            "AccountKey=87D2A2E999180C4A624E1A8153CEBD6;" + "EndpointSuffix=core.windows.net";

【讨论】:

  • 索引 8 的权限中的非法字符:my-provided-accountname.blob.{core.windows.net}
  • 我更新了我的答案。 EndpointSuffix 应该没有括号。 EndpointSuffix=core.windows.net
  • 我删除了这些括号,但仍然:createFileShare 异常:java.net.UnknownHostException: failed to resolve 'my-account-name.file.core.windows.net' after 2 queries
  • 您确定您的存储帐户名为 my-account-name 吗? Azure 存储帐户名称只能包含小写字母和数字。
  • 我已经编辑了这个问题,指出我没有存储帐户。呵呵
【解决方案2】:

我认为 Azure 不喜欢我用于文件名的 camelCase。将其更改为以下内容:

 createFileShare(connectStr,"hellishheat");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-27
    • 2021-12-02
    • 1970-01-01
    • 2017-08-18
    • 2017-11-22
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多