2014-07-21 40 views
1

給出以下代碼和輸出,每當我嘗試下載該文件時,都會得到與此文件相同的異常。AzureBlobStorage:計算的MD5與現有屬性不匹配

如果我沒有md5驗證下載它並檢查內容,這個文件沒有問題,所以我懷疑blob元數據上的md5屬性值不正確。

我想弄清楚它如何在第一個地方變得無效。文件上傳時,是否設置了此屬性的Azure blob存儲內部?

我不想DisableContentMD5Validation作爲解決方案。

(PS。我用Couldberry瀏覽器上傳文件擺在首位)

 static void Main(string[] args) 
    { 
     { 
      try 
      { 

       var client = account.CreateCloudBlobClient(); 
       var container = client.GetContainerReference("algorithms"); 
       var blob = container.GetBlockBlobReference("SInnovations.Algorithms/SInnovations.Algorithms.FootprintFinder.1.0.0-pre-20140430.zip"); 
       blob.FetchAttributes(); 
       Console.WriteLine(blob.Properties.ContentMD5); 

       blob.DownloadToFile("c:\\dev\\test.zip", System.IO.FileMode.Create); 

      } 
      catch (StorageException ex) 
      { 
       if (ex.Message == "Calculated MD5 does not match existing property") 
       { 
        Console.WriteLine("Calculated MD5 does not match existing property"); 
       } 

      } 
     } 
     { 


      var client = account.CreateCloudBlobClient(); 
      var container = client.GetContainerReference("algorithms"); 
      var blob = container.GetBlockBlobReference("SInnovations.Algorithms/SInnovations.Algorithms.FootprintFinder.1.0.0-pre-20140430.zip"); 
      blob.FetchAttributes(); 
      Console.WriteLine(blob.Properties.ContentMD5); 

      blob.DownloadToFile("c:\\dev\\test.zip", System.IO.FileMode.Create,null,new BlobRequestOptions() 
      { 
       DisableContentMD5Validation = true, 
      }); 
      using (var md5 = MD5.Create()) 
      { 
       using (var stream = File.OpenRead("c:\\dev\\test.zip")) 
       { 
        Console.WriteLine(md5.ComputeHash(stream)); 
       } 
      } 

     } 
    } 
} 

給出了這樣的輸出

RH4EqqbthSm24KPgZ2VSGQ== 
Calculated MD5 does not match existing property 
RH4EqqbthSm24KPgZ2VSGQ== 
System.Byte[] 
Press any key to continue . . . 

不好的例子,本地文件MD5是逸岸,HV + nQRNCPQnvy4WU9 + qaQA ==。

結論屬性必須在某個時刻設置錯誤。

解決方案。下載並計算md5並更新blob的屬性值。

+0

難道是Cloudberry Explorer正確設置了MD5嗎?也許是 –

+0

。用一些有趣的信息更新問題。 2秒 –

+0

您能否解釋下載文件時爲什麼要計算MD5與存儲在標題中的MD5匹配,但是如果未禁用驗證,仍然會失敗 –

回答

0

我遇到了同樣的問題,通過CloudBerry Storage Explorer(2.4.0.163)上傳的文件。 我通過Azure門戶和Azure存儲瀏覽器(http://storageexplorer.com/)上傳了相同的文件,但沒有遇到同樣的問題(內容損壞或md5不匹配)。

+1

正如我所知道的,Cloudberry在任何階段都不計算md5,它只是上傳數據,Azure正在生成此頭文件。 – Antoine