我正在使用 VB.NET 和 Azure .NET 程序集将文件上传到 Azure blob。由于文件很大,我将它分成块,并使用CloudBlockBlob.PutBlock
. 我遇到的问题是,如果我提供的 aBlockID
长度超过一个字符,我会收到“指定的 blob 或块内容无效”。来自 的错误PutBLock
。如果 blockID 只有一个字符,则可以正常上传。
Dim iBlockSize As Integer = 1024 ' KB
Dim alBlockIDs As New ArrayList
Dim iBlockID As Integer = 10
' Create the blob client.
Dim blobClient As CloudBlobClient = storageAccount.CreateCloudBlobClient()
' Retrieve reference to a previously created container.
Dim container As CloudBlobContainer = blobClient.GetContainerReference("mycontainer")
' Retrieve reference to a blob named "myblob".
Dim blockBlob As CloudBlockBlob = container.GetBlockBlobReference("myblob")
Dim buffer(iBufferSize) As Byte
fs.Read(buffer, 0, buffer.Length)
Using ms As New MemoryStream(buffer)
' convert block id to Base64 Encoded string
Dim b64BlockID As String = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(iBlockID.ToString(Globalization.CultureInfo.InvariantCulture)))
' write the blob block
blockBlob.PutBlock(b64BlockID, ms, Nothing)
alBlockIDs.Add(b64BlockID)
iBlockID += 1
End Using
如果iBlockID = 1
,该PutBlock
方法可以正常工作(我仍然需要解决每个块的blockID 长度相同,我稍后会担心)。有什么想法吗?我目前正在使用本地 Azure 存储模拟器进行测试。