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.

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!