使用Java的Azure Blob的StorageException [英] StorageException for azure blob with java
问题描述
当我尝试为存储创建容器时,出现StorageException. 1.我创建了一个Azure帐户. 2.我为blob创建了天蓝色的存储 3.我写了简单的测试(下) 4.我在本地计算机上编写了此代码,但出现了异常.怎么了?
When i am trying create container for my storage i get StorageException. 1.I created azure account. 2.I created azure storage for blob 3.I wrotten simple test(below) 4.I made this code on local machine and got exception. What is wrong?
public class Test {
public static final String storageConnectionString =
"DefaultEndpointsProtocol=https;" +
"AccountName=my_account;" +
"AccountKey=my_account_key";
public static void main(String[] args) throws StorageException, InvalidKeyException, URISyntaxException {
pushControll();
}
public static void pushControll() throws URISyntaxException, StorageException, InvalidKeyException {
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference("observer");
container.create();
}
}
我收到StorageException->:
I get StorageException - >:
Exception in thread "main" com.microsoft.azure.storage.StorageException: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:89)
at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:307)
at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:182)
at com.microsoft.azure.storage.blob.CloudBlobContainer.create(CloudBlobContainer.java:279)
at com.microsoft.azure.storage.blob.CloudBlobContainer.create(CloudBlobContainer.java:252)
at ru.marketirs.model.Test.pushControll(Test.java:40)
at ru.marketirs.model.Test.main(Test.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
以退出代码1完成的过程
Process finished with exit code 1
我做错了什么?
推荐答案
您的代码对我来说没问题.请检查2件事情:1)确保帐户名/密钥正确,以及2)检查计算机上的时钟,看它是否运行缓慢.这两件事可能会导致您遇到错误.
Your code looks ok to me. Please check for 2 things: 1) Make sure that the account name/key is proper and 2) Check the clock on your computer and see if it is running slow. These 2 things could cause the error you're getting.
这篇关于使用Java的Azure Blob的StorageException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!