> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-vortex-format.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 将文件上传至 Cloud

> 了解如何将文件上传至 Cloud

export const Image = ({img, alt, size = "lg"}) => {
  const normalizedSize = ["sm", "md", "lg"].includes(size) ? size : "lg";
  return <div className={`ch-image-${normalizedSize}`}>
      <Frame>
        <img src={img} alt={alt} />
      </Frame>
    </div>;
};

ClickHouse Cloud 提供了简便的文件导入方式，并支持以下格式：

| Format                          |
| ------------------------------- |
| `CSV`                           |
| `CSVWithNamesAndTypes`          |
| `CSVWithNames`                  |
| `JSONEachRow`                   |
| `TabSeparated`                  |
| `TabSeparatedWithNames`         |
| `TabSeparatedWithNamesAndTypes` |

<Steps>
  <Step title="上传文件" id="upload-file">
    在 Cloud 首页中，选择你的服务，如下所示：

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/N5J92FpLvYKK3vEv/images/cloud/migrate/csv_01.webp?fit=max&auto=format&n=N5J92FpLvYKK3vEv&q=85&s=65549ee5031810f6b820f7aa5a189eaf" alt="upload_file_02" width="3024" height="1483" data-path="images/cloud/migrate/csv_01.webp" />

    如果你的服务处于空闲状态，则需要先将其唤醒。

    按如下所示，在左侧选项卡中选择 `Data sources`：

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/N5J92FpLvYKK3vEv/images/cloud/migrate/csv_02.webp?fit=max&auto=format&n=N5J92FpLvYKK3vEv&q=85&s=801923017895990b3fd04813dd0399d3" alt="upload_file_03" width="3024" height="1483" data-path="images/cloud/migrate/csv_02.webp" />

    接下来，在数据源页面右侧选择 `Upload a file`：

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/N5J92FpLvYKK3vEv/images/cloud/migrate/csv_03.webp?fit=max&auto=format&n=N5J92FpLvYKK3vEv&q=85&s=7420de605632aa7860933666177c8475" alt="upload_file_04" width="3024" height="1483" data-path="images/cloud/migrate/csv_03.webp" />

    随后会弹出文件对话框，让你选择要用于将数据插入 Cloud 服务中表的文件。

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/N5J92FpLvYKK3vEv/images/cloud/migrate/csv_04.webp?fit=max&auto=format&n=N5J92FpLvYKK3vEv&q=85&s=0dfb645294a9a597dc605ec9e33c88b4" alt="upload_file_05" width="1267" height="736" data-path="images/cloud/migrate/csv_04.webp" />
  </Step>

  <Step title="配置表" id="configure-table">
    文件上传完成后，你就可以配置要将数据插入到哪个表中。界面会显示该表前 3 行数据的预览。

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/N5J92FpLvYKK3vEv/images/cloud/migrate/csv_08.webp?fit=max&auto=format&n=N5J92FpLvYKK3vEv&q=85&s=9307ad5e6b00d72b4bc7f3b5f7aee99d" alt="upload_file_08" width="3018" height="1476" data-path="images/cloud/migrate/csv_08.webp" />

    现在你可以选择目标表。可选项包括：

    * 新表
    * 现有表

    <br />

    你可以指定要将数据上传到哪个数据库；如果是新表，还可以指定要创建的表名。你也可以选择排序键：

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/N5J92FpLvYKK3vEv/images/cloud/migrate/csv_05.webp?fit=max&auto=format&n=N5J92FpLvYKK3vEv&q=85&s=f49834929a267c4008a11b8f5b57377c" alt="upload_file_05" width="3016" height="1474" data-path="images/cloud/migrate/csv_05.webp" />

    从文件中读取的列会显示为 `Source field`，并且你可以为每个字段修改：

    * 推断出的类型
    * 默认值
    * 是否将该列设为 [Nullable](/zh/reference/data-types/nullable)

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/N5J92FpLvYKK3vEv/images/cloud/migrate/csv_06.webp?fit=max&auto=format&n=N5J92FpLvYKK3vEv&q=85&s=6ac2bcd1a65d9de555f3b593fdd5547c" alt="upload_file_06" width="3012" height="1476" data-path="images/cloud/migrate/csv_06.webp" />

    <Info>
      **排除字段**

      如果你不想在导入中包含某个字段，也可以将其移除
    </Info>

    你可以指定要使用的表引擎类型：

    * `MergeTree`
    * `ReplacingMergeTree`
    * `SummingMergeTree`
    * `Null`

    <br />

    你还可以指定分区键表达式和主键表达式。

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/N5J92FpLvYKK3vEv/images/cloud/migrate/csv_07.webp?fit=max&auto=format&n=N5J92FpLvYKK3vEv&q=85&s=812d973174a0ca02753d04a1968f9446" alt="upload_file_07" width="3004" height="1476" data-path="images/cloud/migrate/csv_07.webp" />

    点击 `Import to ClickHouse` (如上所示) 即可导入数据。数据导入任务会进入队列，
    如下所示，你会在 `Status` 列中看到 `queued` 状态标记。你也可以点击
    `Open as query` (如上所示) ，在 SQL 控制台中打开该插入查询。该查询会使用 `URL` 表函数，
    将已上传到 S3 bucket 的文件中的数据插入表中。

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/N5J92FpLvYKK3vEv/images/cloud/migrate/csv_09.webp?fit=max&auto=format&n=N5J92FpLvYKK3vEv&q=85&s=ed6e2483aabe17d29a4b366d36927838" alt="upload_file_09" width="1271" height="487" data-path="images/cloud/migrate/csv_09.webp" />

    如果任务失败，你会在 `Data upload history` 选项卡的 `Status` 列下看到
    `failed` 状态标记。你可以点击 `View Details` 了解上传失败的更多信息。
    你可能需要根据插入失败时的错误消息，修改表配置或清理数据。

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/N5J92FpLvYKK3vEv/images/cloud/migrate/csv_10.webp?fit=max&auto=format&n=N5J92FpLvYKK3vEv&q=85&s=82f3e564321a9594d64f16970280bd7d" alt="upload_file_11" width="1260" height="262" data-path="images/cloud/migrate/csv_10.webp" />
  </Step>
</Steps>
