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

# Uploading a blob to Title Storage

> Flat C code sample for uploading a blob to XBOX services Title Storage using XblTitleStorageUploadBlobAsync, with block size and buffer lifetime guidance.

This topic demonstrates how to upload a blob to XBOX services Title Storage by using the following flat C code example.

## Notes about XblTitleStorageUploadBlobAsync parameters

* The buffer that contains the blob data to upload must be available for the duration of the async operation. You shouldn't modify the buffer while an upload is in progress.

* This method uses a default size if you don't provide `preferredUploadBlockSize`, or if the default size isn't within the acceptable range. The minimum size is 1,024 bytes. The maximum size is 4,194,304 bytes. The default size is 262,144 bytes.

* Binary blobs are uploaded in multiple chunks of `preferredUploadBlockSize` if they exceed that size. In that case, we recommend that you use larger sizes. If time-outs  occur, you should retry the upload using a smaller size.

#### Flat C

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

XblTitleStorageBlobMetadata blobMetadata{};
pal::strcpy(blobMetadata.displayName, displayName.size() + 1, displayName.c_str());
pal::strcpy(blobMetadata.serviceConfigurationId, XBL_SCID_LENGTH, scid);
pal::strcpy(blobMetadata.blobPath, blobPath.size() + 1, blobPath.c_str());
blobMetadata.storageType = storageType;
blobMetadata.blobType = blobType;
time(&blobMetadata.clientTimestamp);

HRESULT hr = XblTitleStorageUploadBlobAsync(
    xboxLiveContext,
    blobMetadata,
    reinterpret_cast<const uint8_t*>(blobBuffer->data()),
    blobBufferSize,
    eTagMatchCondition,
    preferredUploadBlockSize, //    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();
    blobBuffer.release();
}
```

## See also

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

[XblTitleStorageBlobMetadata](/reference/live/xsapi-c/title_storage_c/structs/xbltitlestorageblobmetadata)

[XblTitleStorageUploadBlobAsync](/reference/live/xsapi-c/title_storage_c/functions/xbltitlestorageuploadblobasync)

[XblTitleStorageUploadBlobResult](/reference/live/xsapi-c/title_storage_c/functions/xbltitlestorageuploadblobresult)


## Related topics

- [Title Storage example code](/services/xbox-services/storage/title-storage/how-to/live-title-storage-howto-nav.md)
- [How to](/services/xbox-services/storage/title-storage/how-to/index.md)
- [Downloading a blob from Title Storage](/services/xbox-services/storage/title-storage/how-to/live-downloading-title-storage-blob.md)
- [Deleting a blob from Title Storage](/services/xbox-services/storage/title-storage/how-to/live-deleting-title-storage-blob.md)
- [Getting Title Storage blob metadata](/services/xbox-services/storage/title-storage/how-to/live-getting-title-storage-blob-metadata.md)
