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

# 向 Cloud 上传文件

> 了解如何向 Cloud 上传文件

export const Image = ({img, alt, size}) => {
  return <Frame>
      <img src={img} alt={alt} />
    </Frame>;
};

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

| 格式                              |
| ------------------------------- |
| `CSV`                           |
| `CSVWithNamesAndTypes`          |
| `CSVWithNames`                  |
| `JSONEachRow`                   |
| `TabSeparated`                  |
| `TabSeparatedWithNames`         |
| `TabSeparatedWithNamesAndTypes` |

<Steps>
  <Step>
    ## 上传文件

    在 Cloud 首页中，选择你的服务，如下所示：

    <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/migrate/csv_01.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=d42a4cadb195e135ae5abc86fa2be5a7" alt="upload_file_02" width="3024" height="1483" data-path="images/cloud/migrate/csv_01.png" />

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

    按照下图所示，在左侧标签中选择 `Data sources`：

    <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/migrate/csv_02.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=5e672156414ef3435bf484dccac4f629" alt="upload_file_03" width="3024" height="1483" data-path="images/cloud/migrate/csv_02.png" />

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

    <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/migrate/csv_03.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=4edf3be7ef038ff5e9245b431f788c8d" alt="upload_file_04" width="3024" height="1483" data-path="images/cloud/migrate/csv_03.png" />

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

    <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/migrate/csv_04.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=d83e0e292b5d1bbdef596e2acf2760f8" alt="upload_file_05" width="1267" height="736" data-path="images/cloud/migrate/csv_04.png" />
  </Step>

  <Step>
    ## 配置表

    文件上传完成后，你就可以配置要将数据插入到哪个表中。界面会显示该表前 3 行的预览。

    <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/migrate/csv_08.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=985235e47a14eb6817da999553c0d989" alt="upload_file_08" width="3018" height="1476" data-path="images/cloud/migrate/csv_08.png" />

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

    * 新表
    * 现有表

    <br />

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

    <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/migrate/csv_05.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=85b79e5b6bbac6507d60eecadaedcbb2" alt="upload_file_05" width="3016" height="1474" data-path="images/cloud/migrate/csv_05.png" />

    从文件中读取的列会显示为 `Source field`，对于每个字段，你都可以更改：

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

    <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/migrate/csv_06.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=410497858879eb4741331d47821fb898" alt="upload_file_06" width="3012" height="1476" data-path="images/cloud/migrate/csv_06.png" />

    <Info>
      **排除字段**

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

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

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

    <br />

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

    <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/migrate/csv_07.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=1aea6619d50484e34bd7d80af1301919" alt="upload_file_07" width="3004" height="1476" data-path="images/cloud/migrate/csv_07.png" />

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

    <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/migrate/csv_09.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=36bbcc00ff7509af67320f78414b993f" alt="upload_file_09" width="1271" height="487" data-path="images/cloud/migrate/csv_09.png" />

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

    <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/migrate/csv_10.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=ab057cf126b4da19f4d9d7dbd0214336" alt="upload_file_11" width="1260" height="262" data-path="images/cloud/migrate/csv_10.png" />
  </Step>
</Steps>
