azure - Windows Azure Blob 中的 block 读取问题

标签 azure azure-storage azure-blob-storage

所有,我正在尝试找到一种从 windows azure 中分块读取 blob 的方法。现在我遇到了一些问题,读取的 block 的总大小不等于 blob 的总大小。我的测试blob大小是154805720字节,每个 block 读取大小是10*1024*1024。我发现 block 读取的最后一个缓冲区不是假定的大小 8005080 字节。它始终是 4M。 顺便说一句,我已通过 cloudbrerry 存储资源管理器将此 blob 下载到本地。它与我之前上传的原始文件大小相同。所以,我确信 blob 原始大小是可以的,这意味着 154805720 字节。 这是我的代码。请帮忙查看。

        private static CloudBlobClient CreateBlobClient(StorageAccount account)
        {
            CloudBlobClient blobClient = null;
            CloudStorageAccount oStorageAccount = CreateStorageAccount(account);
            blobClient = oStorageAccount.CreateCloudBlobClient();
            blobClient.Timeout = new TimeSpan(2, 0, 0);
            blobClient.WriteBlockSizeInBytes = 4 * 1024 * 1024;
            blobClient.RetryPolicy = RetryPolicies.Retry(20, TimeSpan.Zero);

            return blobClient;
        }



        public static byte[] DownloadChunkFromBlob(StorageAccount account, string sContainerName, String sBlobName, int blobOffset, int bufferSize)
        {
            CloudBlobClient blobClient = CreateBlobClient(account);

            CloudBlobContainer container = blobClient.GetContainerReference(sContainerName);
            bool b = container.CreateIfNotExist();
            CloudBlob blob = container.GetBlobReference(sBlobName);

            using (var blobStream = blob.OpenRead())
            {
                var buffer = new byte[bufferSize];
                blobStream.Seek(blobOffset, SeekOrigin.Begin);
                int numBytesRead = blobStream.Read(buffer, 0, bufferSize);

                if (numBytesRead != bufferSize)
                {
                    var trimmedBuffer = new byte[numBytesRead];
                    Array.Copy(buffer, trimmedBuffer, numBytesRead);
                    return trimmedBuffer;
                }
                return buffer;
            }
        }

最佳答案

答案是 OpenRead() 一次最多只能读取 4 MB。当我设置 block 读取大小为 4MB 时。一切都很好。

关于azure - Windows Azure Blob 中的 block 读取问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12986821/

相关文章:

azure - Azure 函数 v1 的 Http 响应中不存在内容长度 header

c# - 如何从 C# 代码轮换 Azure 存储帐户访问 key ?

c# - 将图像上传到容器时,Blob 存储触发器不会被触发,为什么?

azure - Cosmos DB 中的事件 ID 是什么?

javascript - 如何使用 SQL 在 Node JS 中使用特定列值

订阅的 Azure ServiceBus SAS key

powershell - Azure 帐户级 SAS token : Possible to Have a Policy?

azure - 在上传到 Blob 存储时启动 Azure 容器服务

python - 如何使用 Python 将 blob 数据移动到 Snowflake

c# - Azure 存储 Rest API(放置 Blob API)