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

# 全局游戏存储

> 获取使用情况,以及列出、下载、上传和删除 XBOX 游戏的每个玩家在沙盒中读取的全局游戏存储文件。

全局游戏存储保存游戏的每个玩家在 XBOX 沙盒中读取的文件,例如新闻源、地图或调整值。`xbox xbl global-storage` 显示沙盒使用了多少配额,并逐个列出、下载、上传和删除其文件。读取这些文件需要具有读取游戏 XBOX 服务配置的 Partner Center 权限,上传或删除这些文件则需要具有更改该配置的权限。

仅当游戏沙盒已发布的 `titlestorage.xml` 包含
`<StorageType ownerOnly="false">global</StorageType>` 时,游戏才会读取这些文件;当你在 **Title Storage** 页面上为 **Global** 选择 **Active** 时,Partner Center 会保存该元素。若要使用 CLI 启用它,请使用
[`xbl config save`](https://docs.xbox.com/zh-CN/tools/xbox-cli/commands/xbl#config-download-and-config-save) 将该元素添加到沙盒的 `titlestorage.xml` 中,然后使用
[`xbl config publish`](https://docs.xbox.com/zh-CN/tools/xbox-cli/commands/xbl#config-publish) 发布该沙盒。

与每个 `xbl` 命令一样,这些命令属于实验性命令:其选项和输出可能会更改或被删除。请参阅[实验性命令](https://docs.xbox.com/zh-CN/tools/xbox-cli/cli-command-lifecycle.md)。

| 命令 | 效果 |
| - | - |
| `global-storage get` | 显示沙盒的文件使用了多少配额。 |
| `global-storage list` | 列出沙盒的文件。 |
| `global-storage download` | 下载一个文件。 |
| `global-storage upload` | 上传一个不超过 4 MiB 的文件。 |
| `global-storage delete` | 删除一个文件。会先进行询问。 |

> [!WARNING]
>
> 上传或删除会立即影响沙盒中的每个玩家,无需先发布。已删除的文件无法恢复。

`RETAIL` 是只读的:`upload` 和 `delete` 在其中会失败。若要更改 `RETAIL` 的文件,请更改开发沙盒的文件,然后使用
[`xbl config publish`](https://docs.xbox.com/zh-CN/tools/xbox-cli/commands/xbl#cross-sandbox-publishing-replaces-global-title-storage-files) 将该沙盒发布到 `RETAIL`,这会使 `RETAIL` 的文件成为其文件的副本。

## 选项

| 选项 | 命令 | 必需 | 说明 |
| - | - | - | - |
| `--scid <guid>` 或 `--title-id <id>` | 全部 | 是,二者之一 | 游戏的服务配置标识符 (SCID),或其 XBOX 游戏 ID(CLI 会先查找它)。请参阅[游戏定位](https://docs.xbox.com/zh-CN/tools/xbox-cli/commands/xbl.md#title-targeting)。 |
| `--sandbox-id <id>` | 全部 | 是 | 运行游戏的沙盒,例如 `XDKS.1` 或 `RETAIL`。`ALL`、`HIDDEN` 和 `HISTORY` 仅保存配置,因此会失败。 |
| `--seller-id <id>` | 全部 | 否 | Partner Center 卖家 ID。默认为你唯一的卖家。 |
| `--path <path>` | 除 `get` 外的全部 | 对于 `download`、`upload` 和 `delete` 为必需 | 文件的路径,例如 `news/today.json`。对于 `list`,为一个文件夹(例如 `news/`),仅列出其中的文件。 |
| `--file-type <type>` | `download`、`upload`、`delete` | 是 | 文件的类型:`binary`、`json` 或 `config`。 |
| `--file <file>` | `upload` | 是 | 要上传的本地文件,不超过 4 MiB;或使用 `-` 从 stdin 读取。 |
| `--overwrite` | `upload` | 否 | 替换 `--path` 处的文件,无论其类型如何。如果不使用此选项,当该路径已有文件时,`upload` 会失败。 |
| `--dest <path>` | `download` | 否 | 保存文件的位置:一个文件、一个用于按文件名保存该文件的目录,或使用 `-` 表示 stdout。默认为当前目录中的文件名。现有文件会被替换。 |
| `--confirm`、`--yes`、`-y` | `delete` | 在交互式终端之外为必需 | 删除时不进行询问。 |
| `--output <format>` | 全部 | 否 | `json`(默认)或 `json-compact`;`table` 适用于 `get` 和 `list`。 |

如果未指定 `--scid` 或 `--title-id`、`--sandbox-id` 或 `--seller-id`,命令会使用按[上下文](https://docs.xbox.com/zh-CN/tools/xbox-cli/commands/context.md)中所述设置的值。

路径由文件夹组成,每个文件夹由字母、数字和 `_` 组成,后跟 `/`,然后是由字母、数字、`_`、`-` 和 `.` 组成的文件名。一个路径保存一个文件(无论其类型如何),因此 `download` 和 `delete` 需要 `list` 显示的类型。上传 `json` 或 `config` 文件时,XBOX 服务会检查其内容。

## 示例

查看 XDKS.1 使用了多少配额,并列出其文件:

```bash theme={null}
xbox xbl global-storage get --title-id 1234ABCD --sandbox-id XDKS.1 --output table
xbox xbl global-storage list --title-id 1234ABCD --sandbox-id XDKS.1 --output table
```

将 `today.json` 上传为游戏读取的新闻源:

```bash theme={null}
xbox xbl global-storage upload --title-id 1234ABCD --sandbox-id XDKS.1 --file today.json --path news/today.json --file-type json
```

将其替换为新版本:

```bash theme={null}
xbox xbl global-storage upload --title-id 1234ABCD --sandbox-id XDKS.1 --file today.json --path news/today.json --file-type json --overwrite
```

将其下载到当前目录中的 `today.json`,或将其写入 stdout:

```bash theme={null}
xbox xbl global-storage download --title-id 1234ABCD --sandbox-id XDKS.1 --path news/today.json --file-type json
xbox xbl global-storage download --title-id 1234ABCD --sandbox-id XDKS.1 --path news/today.json --file-type json --dest -
```

删除它:

```bash theme={null}
xbox xbl global-storage delete --title-id 1234ABCD --sandbox-id XDKS.1 --path news/today.json --file-type json
```

## 输出

`get` 写入沙盒的使用情况:

```json theme={null}
{
  "usedBytes": 9437696,
  "quotaBytes": 268435456
}
```

`usedBytes` 是沙盒的文件所使用的空间,`quotaBytes` 是其配额:文件使用量达到该值后,上传会失败。其表格显示 `USED BYTES` 和 `QUOTA BYTES`。

`list` 写入文件数组;如果没有文件,则写入 `[]`:

```json theme={null}
[
  {
    "path": "maps/nod_arena.bin",
    "type": "binary",
    "size": 9437184,
    "etag": "\"0x8DDF1A2B3C4D5E6\"",
    "clientFileTime": "2026-10-28T17:02:11+00:00"
  },
  {
    "path": "news/today.json",
    "type": "json",
    "size": 512,
    "etag": "\"0x8DDF1A2B3C4D5E7\""
  }
]
```

`size` 以字节为单位,`clientFileTime` 是文件的上传时间(如果已知)。表格显示 `PATH`、`TYPE`、`SIZE` 和 `UPLOADED`。

`upload`、`download` 和 `delete` 是文件操作,类似于 `cp` 和 `rm`。除了使用 `download --dest -` 时写入文件之外,它们不会向 stdout 写入任何内容,并会在 stderr 上报告它们执行的操作:

| 命令 | 成功时的 stderr |
| - | - |
| `upload` | 发送文件之前显示 `Uploading '<file>' to 'news/today.json'.`,然后显示 `Uploaded '<file>' to 'news/today.json' (json, 512 bytes).` |
| `download` | `Downloaded 'news/today.json' to '<path>' (512 bytes).` |
| `delete` | `Deleted 'news/today.json' (json).` |

这些消息可能会在不同版本之间发生变化。这三个命令不接受 `--output table`。下载失败时,目标位置已有的文件会保持原样。

## 退出代码

| 退出代码 | 含义 |
| - | - |
| `0` | 命令已成功。 |
| `1` | 命令失败。对于 `upload` 和 `delete`,未进行任何更改:请求未发送,或者服务拒绝了请求。 |
| `3` | `upload` 或 `delete` 已发送,但结果未知。在再次运行之前,请使用 stderr 中显示的 `global-storage list` 命令检查文件。 |

## 错误

被拒绝的请求以 `1` 退出,并将 JSON 错误写入 stderr,如[错误](https://docs.xbox.com/zh-CN/tools/xbox-cli/commands/xbl.md#errors)中所述。以下是你最可能遇到的错误:

| `code` | 原因 |
| - | - |
| `global_storage_file_not_found` | 对没有该 `--file-type` 文件的路径执行了 `download` 或 `delete`;`delete` 不会删除任何内容。`list` 会显示每个文件的路径和类型。 |
| `global_storage_file_exists` | 该路径已有文件。传递 `--overwrite` 可替换该文件。 |
| `global_storage_retail_read_only` | 在 `RETAIL` 中进行了上传或删除。请更改开发沙盒的文件,然后将其发布到 `RETAIL`。 |
| `global_storage_quota_exceeded` | 沙盒的文件已达到其配额。请删除不需要的文件。 |
| `xbox_access_denied` | 你没有游戏的 XBOX 服务配置或该沙盒的权限。 |
| `downstream_request_rejected` | XBOX 服务拒绝了请求,例如 `json` 文件不是有效的 JSON。`detail` 会说明原因。 |


## Related topics

- [Global Storage 工具 (GlobalStorage.exe)](https://docs.xbox.com/zh-CN/tools/tools-services/live-global-storage-tool.md)
- [XBOX 服务配置](https://docs.xbox.com/zh-CN/tools/xbox-cli/commands/xbl.md)
- [在游戏测试中使用 XBOX 服务](https://docs.xbox.com/zh-CN/tools/xbox-cli/xbox-services-in-a-playtest.md)
- [XBOX CLI](https://docs.xbox.com/zh-CN/tools/xbox-cli/index.md)
- [游戏存储](https://docs.xbox.com/zh-CN/services/xbox-services/storage/title-storage/index.md)
