0

我的存储模拟器上已有一个页面 blob。现在我正在尝试使用 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);

谢谢

4

1 回答 1

1

我相信你一定是在你的 blob 上犯了一些错误,或者你的 blob 可能不是页面 blob。我刚刚使用了以下代码并验证 WritePage API 在 Emulator 上是否可以正常工作:

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.
于 2012-07-09T20:36:52.843 回答