我曾经启动复制 blob,在复制过程中,我们能够读取目标 blob 的几个字节(例如前 512 个字节)。请参阅下面的代码,该代码启动复制 blob,然后在复制过程中读取前 512 个字节。
但是现在 blobStream.Read 总是用零而不是实际字节填充数据缓冲区。我也尝试过使用最新的天蓝色存储客户端库,但输出是相同的。但是一旦复制完成,我就可以读取实际字节。
有人请让我知道这是否是最新的 azure 存储服务中引入的错误以及可能的解决方法(如果有)?
CloudBlobClient client = CloudStorageAccount.Parse(
string.Format(
"DefaultEndpointsProtocol={0};AccountName={1};AccountKey={2}",
"http",
"<destination-account-name>",
"<destination-account-key>"
)
).CreateCloudBlobClient();
var vhdsContainer = client.GetContainerReference("<destination-container-name>");
CloudBlob destinationBlob = vhdsContainer.GetPageBlobReference("test-1-b5c1d3f4-23d5-40e4-adc7-236553f8d62d-1.vhd");
destinationBlob.StartCopyFromBlob(
new Uri("http://<source-storage>.blob.core.windows.net/<source-container-name>/test-4-d803ca0a-5d98-4be8-8895-2a9d15ec3974-1.vhd"), null, null, null);
CloudBlob destBlob = vhdsContainer.GetBlobReference("test-1-b5c1d3f4-23d5-40e4-adc7-236553f8d62d-1.vhd");
int maxWaitTime = 3*60000;//let's wait for a maximum of 3 minute
do
{
destBlob.FetchAttributes();
if (destBlob.CopyState.BytesCopied > 2048 || maxWaitTime <= 0)
{
break;
}
maxWaitTime -= 1000;
Thread.Sleep(1000);
}
while (true);
var data = new byte[512];
using (BlobStream blobStream = destBlob.OpenRead())
{
blobStream.Seek(0, System.IO.SeekOrigin.Begin);
blobStream.Read(data, 0, 512);
}