0

尝试从Storage-blobs-java-v10-quickstart运行简单示例并使用API 参考文档中列出的参考如下:

String accountName = "acsazurestore";
String accountKey = "qjC6s44AmSbAkJ7Xqdsks/jjZDIYRTY8qg...."; [not the full one]

SharedKeyCredentials sharedKeyCredentials = new SharedKeyCredentials(accountName, accountKey);

编译 ( mvn compile exec:java) 时,程序失败并显示以下错误消息:

Caused by: java.lang.IllegalArgumentException: Input byte array has wrong 4-byte ending unit
at java.util.Base64$Decoder.decode0(Base64.java:704)
at java.util.Base64$Decoder.decode(Base64.java:526)
at java.util.Base64$Decoder.decode(Base64.java:549)
at com.microsoft.azure.storage.blob.SharedKeyCredentials.<init>(SharedKeyCredentials.java:60)
at quickstart.Quickstart.main(Quickstart.java:162)

感谢任何帮助!

4

1 回答 1

1

即使使用伪造的帐户密钥,它也应该可以工作。我假设它可能发生在其他代码行中。如果不是这样的话。我建议您可以创建一个新项目并添加以下依赖项。

<dependency>
        <groupId>com.microsoft.azure</groupId>

        <artifactId>azure-storage-blob</artifactId>

        <version>10.1.0</version>

</dependency>

只需添加以下代码并再次测试。

public static void main(String... args) throws Exception
    {
        String accountName = "accountName";
        String accountKey = "xxxxxxxxxxx";

        try {
            SharedKeyCredentials sharedKeyCredentials = new SharedKeyCredentials(accountName, accountKey);
            System.out.print(sharedKeyCredentials.getAccountName());
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        }

    }

测试结果:

在此处输入图像描述

于 2018-09-19T06:56:40.047 回答