> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 从 Title Storage 下载 blob

> 使用 XblTitleStorageDownloadBlobAsync 从 XBOX 服务 Title Storage 下载 blob 的扁平 C 代码示例，包括缓冲区大小和块大小指南。

本主题通过以下扁平 C 代码示例演示如何从 XBOX 服务 Title Storage 下载 blob。

## 关于 XblTitleStorageDownloadBlobAsync 参数的说明

* 你提供用于存储所下载 blob 数据的缓冲区必须足够大，以存储正在下载的 blob。如果需要，你可以通过获取 blob 元数据来检索缓冲区所需的长度。

* 如果 `blobBuffer` 没有足够容量来容纳 blob 数据，此 API 将返回 E\_NOT\_SUFFICIENT\_BUFFER (0x8007007A)。

* 若要使用默认大小，请为 `preferredDownloadBlockSize` 传入 0。

#### 扁平 C

```cpp theme={null}
std::unique_ptr<std::vector<uint8_t>> downloadBlobBuffer = std::make_unique<std::vector<uint8_t>>(blobMetadata.length);

auto asyncBlock = std::make_unique<XAsyncBlock>();
asyncBlock->queue = queue;
asyncBlock->context = downloadBlobBuffer.get();
asyncBlock->callback = [](XAsyncBlock* asyncBlock)
{
    std::unique_ptr<XAsyncBlock> asyncBlockPtr{ asyncBlock };   // Take over ownership of XAsyncBlock*.
    std::unique_ptr<std::vector<uint8_t>> downloadBlobBuffer{ static_cast<std::vector<uint8_t>*>(asyncBlock->context) };
    HRESULT hr = XblTitleStorageDownloadBlobResult(asyncBlock, &blobMetadata);
};

HRESULT hr = XblTitleStorageDownloadBlobAsync(
    xboxLiveContext,
    blobMetadata,
    downloadBlobBuffer->data(),
    blobMetadata.length,
    XblTitleStorageETagMatchCondition::NotUsed,
    selectQuery.c_str(),   // Optional  .
    preferredDownloadBlockSize,   // Optional.
    asyncBlock.get()
);

if (SUCCEEDED(hr))
{
    // The call succeeded, so release std::unique_ptr ownership of XAsyncBlock* because
    // the callback takes over ownership. If the call fails, however, std::unique_ptr keeps
    // ownership and deletes XAsyncBlock*.
    asyncBlock.release();
    downloadBlobBuffer.release();
}
```

## 另请参阅

[XAsyncBlock](/reference/system/xasync/structs/xasyncblock)

[XblTitleStorageDownloadBlobAsync](/reference/live/xsapi-c/title_storage_c/functions/xbltitlestoragedownloadblobasync)

[XblTitleStorageDownloadBlobResult](/reference/live/xsapi-c/title_storage_c/functions/xbltitlestoragedownloadblobresult)

[XblTitleStorageETagMatchCondition](/reference/live/xsapi-c/title_storage_c/enums/xbltitlestorageetagmatchcondition)


## Related topics

- [Title Storage 示例代码](/zh-CN/services/xbox-services/storage/title-storage/how-to/live-title-storage-howto-nav.md)
- [从 Title Storage 删除 blob](/zh-CN/services/xbox-services/storage/title-storage/how-to/live-deleting-title-storage-blob.md)
- [XblTitleStorageDownloadBlobAsync](/zh-CN/reference/live/xsapi-c/title_storage_c/functions/xbltitlestoragedownloadblobasync.md)
- [XblTitleStorageDownloadBlobResult](/zh-CN/reference/live/xsapi-c/title_storage_c/functions/xbltitlestoragedownloadblobresult.md)
- [获取 Title Storage blob 元数据](/zh-CN/services/xbox-services/storage/title-storage/how-to/live-getting-title-storage-blob-metadata.md)
