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

# Commit 与上传

> 上传新应用到 Square Cloud，或将新文件 commit 到现有应用。

## 上传新应用

`api.applications.create(file)` 上传一个 zip 并创建一个全新的应用。`file` 参数可以是本地文件路径或 `Buffer`。

```typescript theme={null}
import { SquareCloudAPI } from "@squarecloud/api";
import { join } from "node:path";

const api = new SquareCloudAPI(process.env.SQUARE_API_KEY!);

const result = await api.applications.create(join(__dirname, "my-app.zip"));

console.log(result.id);   // newly created application ID
console.log(result.name); // display name
console.log(result.lang); // language slug (e.g. "javascript")
console.log(result.ram);  // allocated RAM in MB
```

该 zip 至少必须包含：

* **主文件** —— 应用的入口点
* **依赖文件** —— `package.json`、`requirements.txt` 等
* **`squarecloud.app`** —— 包含名称、描述、主文件、版本等的配置文件。参见[配置文件指南](/zh/getting-started/config-file)

## 将文件 commit 到现有应用

`app.commit(file, fileName?)` 将文件上传到一个已部署的应用中。传入一个 zip 可一次性替换多个文件，或传入单个文件以仅更新该文件。

| 参数         | 类型                 | 说明                                          |
| ---------- | ------------------ | ------------------------------------------- |
| `file`     | `string \| Buffer` | 本地文件路径或 `Buffer` 内容                         |
| `fileName` | `string?`          | 附加到上传的名称。`.zip` 会在服务端被解压；任何其他扩展名都会作为单个文件写入。 |

<Tabs>
  <Tab title="Commit 单个文件 (Buffer)">
    ```typescript theme={null}
    const content = Buffer.from("console.log('hello')\n");
    await app.commit(content, "index.js");
    ```
  </Tab>

  <Tab title="从磁盘 commit 一个 zip">
    ```typescript theme={null}
    import { readFile } from "node:fs/promises";

    const zip = await readFile("./dist.zip");
    await app.commit(zip, "dist.zip");
    ```
  </Tab>

  <Tab title="按路径 commit 一个文件">
    ```typescript theme={null}
    import { join } from "node:path";

    const filePath = join(__dirname, "index.js");
    await app.commit(filePath, "index.js");
    ```
  </Tab>
</Tabs>

<Warning>
  在 v3 中，`commit()` 接受第三个 `restart` 参数。**在 v4 中该第三个参数已被移除** —— 如果你需要重启，请在 commit 之后使用 `app.restart()`。
</Warning>

```typescript theme={null}
await app.commit(zip, "dist.zip");
await app.restart();
```
