2015-12-30 143 views
0

當我使用下面的代碼將文件上傳到服務器Azure blob時,我遇到了與Azure Blob存儲相關的錯誤。com.microsoft.windowsazure.services.core.storage.StorageException:服務器無法驗證請求

CloudStorageAccount account; 
CloudBlobClient serviceClient; 
CloudBlobContainer container; 
CloudBlockBlob blob; 

final String bucketName = PropertyReader.getValue("aws.properties", bucket); 

account = CloudStorageAccount.parse(storageConnectionString); 
serviceClient = account.createCloudBlobClient(); 
// Container name must be lower case. 
container = serviceClient.getContainerReference(bucketName); 
container.createIfNotExist(); 

// Set anonymous access on the container. 
BlobContainerPermissions containerPermissions; 
containerPermissions = new BlobContainerPermissions(); 
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER); 
container.uploadPermissions(containerPermissions); 

// Upload an image file. 
blob = container.getBlockBlobReference(imageName); 
blob.upload(imageStream, imageArray.length); 

我使用的代碼,並建立MYCOMPUTER(Windows 8中)的本地主機上,能正常工作。但是,當我部署到服務器Linux它捕捉異常

com.microsoft.windowsazure.services.core.storage.StorageException:服務器無法驗證請求。確保授權標頭的值正確形成,包括簽名。

我發現這個問題上相關主題 - Azure API The server failed to authenticate the request 但它仍然沒有幫助解決我的問題。我該如何解決?

+1

如果不是可運行的HTML/CSS/JS代碼,請不要使用Stack Snippets來添加代碼。我已將片段更改爲普通代碼塊,更正了格式並改進了一些語法。 – Harry

+0

任何人都可能幫助我:( – Harry

回答

0

這是使用Java客戶端庫嗎?如果這可以在你的本地機器上運行,但是在你的Linux服務器上不能運行,它可能與緩存代理或客戶機和服務器之間的類似情況有關。無論如何,如果你看到相同的代碼在一個地方但不是另一個地方工作,看起來很可能它是你的最終配置問題,而不是庫缺陷。

+0

你好彼得。我需要什麼來配置代理客戶端或服務器。你能幫我嗎?? – Harry

+0

你需要確保你的客戶端和你的服務器之間沒有緩存 - 我沒有見識你如何配置其中的任何一個,如果你可以爲失敗的請求提供請求ID,我可以再看一下,但這是我的猜測。 –