将页面Blob上载到Azure获取错误:确保正确形成Authorization标头的值

时间:2015-03-11 09:00:18

标签: java azure azure-storage azure-storage-blobs

我正在使用Microsoft Azure Java SDK上传页面Blob(大小:20G / 40G)。在上传过程中,SDK会抛出存储异常:

java.io.IOException: null
    at com.microsoft.azure.storage.core.Utility.initIOException(Utility.java:584) ~[classes/:na]
    at com.microsoft.azure.storage.blob.BlobOutputStream$2.call(BlobOutputStream.java:414) ~[classes/:na]
    at com.microsoft.azure.storage.blob.BlobOutputStream$2.call(BlobOutputStream.java:398) ~[classes/:na]
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) ~[na:1.7.0_25]
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) ~[na:1.7.0_25]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) ~[na:1.7.0_25]
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) ~[na:1.7.0_25]
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) ~[na:1.7.0_25]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_25]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_25]
    at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
Caused by: 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:162) ~[azure-storage-1.2.0.jar:na]
    at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:306) ~[azure-storage-1.2.0.jar:na]
    at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:178) ~[classes/:na]
    at com.microsoft.azure.storage.blob.CloudPageBlob.putPagesInternal(CloudPageBlob.java:642) ~[classes/:na]
    at com.microsoft.azure.storage.blob.CloudPageBlob.uploadPages(CloudPageBlob.java:971) ~[classes/:na]
    at com.microsoft.azure.storage.blob.BlobOutputStream$2.call(BlobOutputStream.java:402) ~[classes/:na]
    ... 9 common frames omitted

SDK版本:

<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>1.2.0</version>

请注意,此错误会在随机上传中显示: 转移字节数:27325890560,总计42949673472

Linux Box上是否有时间漂移导致此问题?任何其他指针都会有所帮助。

调用Azure Java SDK API以上传页面blob的代码段:

String storageAccntName = "storageAccount";

URI blobEndpoint = null;
String uriString = "http://" + storageAccntName + ".blob.core.windows.net";
blobEndpoint = new URI(uriString);

CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint, new StorageCredentialsAccountAndKey(storageAccntName, blobInfo.getAccessKey()));
blobClient.setAuthenticationScheme(AuthenticationScheme.SHAREDKEYFULL);
blobClient.getDefaultRequestOptions().setRetryPolicyFactory(new RetryLinearRetry());

//Create Storage Container
CloudBlobContainer container = blobClient.getContainerReference(Constants.STORAGE_CONTAINER_NAME);
container.createIfNotExists();

//Creating Page Blob corresponding to each disk
CloudPageBlob pageBlob = container.getPageBlobReference("pageBlobName");
File vhdFile  = new File("pageBlobName");
if(vhdFile.length()==0) {
    throw new CPMException("Invalid file with length 0. Stopping upload for file with path: " + vhdFile.getAbsolutePath()
            + " and file name: " + diskBlob.getLocation());
}
LOG.debug("Blob size for Disk: " + diskBlob.getName() + " is: " + vhdFile.length());

pageBlob.create(vhdFile.length());
blobClient.getDefaultRequestOptions().setConcurrentRequestCount(Constants.MAX_CONSUMER_THREADS);
pageBlob.upload(new FileInputStream(vhdFile), vhdFile.length());

1 个答案:

答案 0 :(得分:0)

如果您使用共享访问签名上传文件,并且SAS的有效期已过期,则可能会发生这种情况。根据您的blob大小,此上传文件将被拆分为多个请求,并且在稍后的请求发出时,SAS可能已过期。

如果您使用的是存储帐户和密钥而不是SAS,请粘贴遇到此问题的代码段。