2012-07-07 73 views
0

我的存儲模擬器上有一個已經存在的頁面blob。現在我正在嘗試使用WritePages向它寫入更多的字節,但它似乎不起作用。 Storage Emulator是否支持該功能,或者我可能會做錯什麼?現有Blob的Azure WritePages是否適用於存儲模擬器

下面是我試圖做到這一點。

  var account = CloudStorageAccount.Parse("UseDevelopmentStorage=true"); 

      var blobClient = account.CreateCloudBlobClient(); 

      var blobContainer = blobClient.GetContainerReference("mycontainer"); 
      blobContainer.CreateIfNotExist(); 
      blobContainer.SetPermissions(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob }); 

      var pageBlob = blobContainer.GetPageBlobReference("filepage.txt"); 
      pageBlob.FetchAttributes(); 

      byte[] data = File.ReadAllBytes(@"C:\Temp\moretext.txt"); 
      Array.Resize(ref data, 512); 

      pageBlob.WritePages(new MemoryStream(data), 0); 

感謝

回答

1

我相信你一定是弄錯了或者與你的斑點或斑塊的可能不是一個是頁面斑點。我只是使用下面的代碼並驗證WritePage API在模擬器上工作正常:

var account = CloudStorageAccount.Parse("UseDevelopmentStorage=true"); 
var blobClient = account.CreateCloudBlobClient(); 

var blobContainer = blobClient.GetContainerReference("mycontainer"); 
blobContainer.CreateIfNotExist(); 
blobContainer.SetPermissions(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob }); 

// Create a Page Blob 
CloudPageBlob pageBlob = blobContainer.GetPageBlobReference("mypageblob"); 
pageBlob.Create(5120); 
// After above line execution, check Azure Emulated Storage and download the PageBlob locally and verify that it is a 5120 size Page blob 

byte[] data = File.ReadAllBytes(@"C:\2012\100text.txt"); // About 300byte text 
Array.Resize(ref data, 512); 

pageBlob.WritePages(new MemoryStream(data), 0); 
// After above line execution, again check Azure Emulated Storage and download the PageBlob locally and verify that it is still a 5120 size Page blob with text in it.