本文介绍了上传与BLOCKID&GT BLOB块错误; 1字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将文件上载到使用VB.NET和Azure的.NET程序集的Azure的BLOB。由于文件很大,我打破它成块,并用 CloudBlockBlob.PutBlock 上传。我遇到的问题是,如果我提供一个 BLOCKID 这是长于一个字符,我得到一个指定的blob或块内容是无效的。从 PutBLock误差。如果BLOCKID只有一个人物造型,其上传的罚款。

I'm uploading a file to an Azure blob using VB.NET and the Azure .NET assemblies. As the file is large, I'm breaking it into blocks, and uploading with CloudBlockBlob.PutBlock. The problem I'm having is if I supply a BlockID which is longer than one character, I'm getting a "The specified blob or block content is invalid." error from PutBLock. If the blockID is only one charactor, it uploads fine.

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存储模拟器中进行测试。

If iBlockID = 1, the PutBlock method works fine (I still need to address the blockID being the same length for each block, I'll worry about that later). Any ideas what's going on? I'm currently testing with the local Azure storage emulator.

推荐答案

斜面确认,但有可能是在你的code机会,你migh whlie创建这些缓冲区是重叠的一些内存。请参考下列工作code在块上传斑点。继code使用的块大小 10240(10KB),但它可以很容易地改变

Cant confirm but there might be chances in your code that you migh be overlapping some memory whlie creating those buffers. Please refer following working code to upload a Blob in blocks. Following code uses block size of 10240 (10KB) but it can be changed easily

Dim fileName As String = "D:\Untitled.png"
Dim fileSize As Long = New FileInfo(fileName).Length
Dim blockNumber As UInteger = 0
Dim blocksize As UInteger = 10240 '10KB
Dim blockIdList As List(Of String) = New List(Of String)

Using fs As New FileStream(fileName, FileMode.Open, FileAccess.Read)

    Do While (fileSize > 0)
        Dim bufferSize As UInteger

        'Last block of file can be less than 10240 bytes
        If (fileSize > blocksize) Then
            bufferSize = blocksize
        Else
            bufferSize = fileSize
        End If

        Dim buffer(bufferSize) As Byte
        Dim br As New BinaryReader(fs)

        'move the file system reader to the proper position
        fs.Seek(blocksize * blockNumber, SeekOrigin.Begin)
        br.Read(buffer, 0, bufferSize)

        Using ms As New MemoryStream(buffer, 0, bufferSize)
            'convert block id to Base64 Encoded string 
            Dim b64BlockID As String = Convert.ToBase64String(Encoding.ASCII.GetBytes(String.Format("BlockId{0}", blockNumber.ToString("0000000"))))
            blockBlob.PutBlock(b64BlockID, ms, Nothing)

            blockIdList.Add(b64BlockID)
        End Using

        blockNumber += 1
        fileSize -= blocksize
    Loop

    blockBlob.PutBlockList(blockIdList)

End Using

这篇关于上传与BLOCKID&GT BLOB块错误; 1字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 13:53