doujiacai4986 2018-01-04 22:18
浏览 125
已采纳

Azure Blob首先写入

This official example for writing blob blocks has a step where it checks which blocks have not been committed:

    fmt.Println("Get uncommitted blocks list...")
    list, err := b.GetBlockList(storage.BlockListTypeUncommitted, nil)
    if err != nil {
        return fmt.Errorf("get block list failed: %v", err)
    }
    uncommittedBlocksList := make([]storage.Block, len(list.UncommittedBlocks))
    for i := range list.UncommittedBlocks {
        uncommittedBlocksList[i].ID = list.UncommittedBlocks[i].Name
        uncommittedBlocksList[i].Status = storage.BlockStatusUncommitted
    }

If I'm creating a blob (with multiple blocks) that definitely doesn't yet exist. Is there any problem with skipping that code?

The code would be something like:

    b := cnt.GetBlobReference(blockBlobName)
    err := b.CreateBlockBlob(nil)

    blockID := "00000"
    data := randomData(1984)
    err = b.PutBlock(blockID, data, nil)

    blockID2 := "00001"
    data2 := randomData(6542)
    err = b.PutBlock(blockID2, data2, nil)

    var uncommittedBlocksList []storage.Block
    uncommittedBlocksList = append(uncommittedBlocksList, 
        Block{
           ID:"00000"
           Status:BlockStatusUncommitted,
        },
        Block{
           ID:"00001"
           Status:BlockStatusUncommitted,
        },
    )
    err = b.PutBlockList(uncommittedBlocksList, nil)
  • 写回答

1条回答 默认 最新

  • douxuanwei1980 2018-01-05 02:44
    关注

    If I'm creating a blob (with multiple blocks) that definitely doesn't yet exist. Is there any problem with skipping that code?

    Absolutely not. You can certainly skip the code for fetching uncommitted block list. This scenario for fetching uncommitted list is useful when you tried to upload a blob and it failed in between and you want to resume the upload from the last failed block. By skipping this code, you are essentially telling Azure Storage to discard any other uncommitted blocks and use the blocks specified in the block list to create the blob.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?