> ## 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.

# 從遊戲儲存空間下載 Blob

> 使用 XblTitleStorageDownloadBlobAsync 從 XBOX 服務遊戲儲存空間下載 Blob 的 flat C 程式碼範例，並提供緩衝區大小與區塊大小指引。

本主題使用下列 flat C 程式碼範例，示範如何從 XBOX 服務遊戲儲存空間下載 Blob。

## XblTitleStorageDownloadBlobAsync 參數的注意事項

* 您提供用來儲存下載 Blob 資料的緩衝區，必須大到足以儲存正在下載的 Blob。如有需要，您可以透過取得 Blob 中繼資料來擷取緩衝區所需的長度。

* 如果 `blobBuffer` 的容量不足以保存 Blob 資料，此 API 會傳回 E\_NOT\_SUFFICIENT\_BUFFER (0x8007007A)。

* 若要使用預設大小，請為 `preferredDownloadBlockSize` 傳遞 0。

#### Flat 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](/zh-TW/reference/system/xasync/structs/xasyncblock)

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

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

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


## Related topics

- [遊戲儲存空間範例程式碼](/zh-TW/services/xbox-services/storage/title-storage/how-to/live-title-storage-howto-nav.md)
- [全域儲存空間工具 (GlobalStorage.exe)](/zh-TW/tools/tools-services/live-global-storage-tool.md)
- [操作說明](/zh-TW/services/xbox-services/storage/title-storage/how-to/index.md)
- [從遊戲儲存空間刪除 Blob](/zh-TW/services/xbox-services/storage/title-storage/how-to/live-deleting-title-storage-blob.md)
- [取得遊戲儲存空間 Blob 中繼資料](/zh-TW/services/xbox-services/storage/title-storage/how-to/live-getting-title-storage-blob-metadata.md)
