Path: API › 文件管理

`POST /files`

保存文本内容到指定文件，用于在线编辑代码或配置文件。

## Request body

_Required._

- `action132.request_time` (string, required) — Unix 时间戳。
- `action132.request_token` (string, required) — 按 API 概览生成的签名。
- `action132.action` (string, required) — 具体操作名称。
  - one of `"SaveFileBody"`
- `action132.path` (string, required) — 文件绝对路径
- `action132.data` (string, required) — 要写入的文件内容
- `action132.encoding` (string, required) — 文件编码：`utf-8` / `ascii` / `ansi` / `GBK` / `BIG5`

## Example request

```text
{
  "request_time": "string",
  "request_token": "string",
  "action": "SaveFileBody",
  "path": "string",
  "data": "string",
  "encoding": "string"
}
```

## Code samples

### cURL（填写面板地址与签名）

```curl
curl --request POST \
  --url "https://your-panel.example.com:8888/files" \
  --header "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "request_time=<Unix时间戳>" \
  --data-urlencode "request_token=<按 API 概览生成的签名>" \
  --data-urlencode "action=SaveFileBody" \
  --data-urlencode "path=<path>" \
  --data-urlencode "data=<data>" \
  --data-urlencode "encoding=<encoding>"
```

## Responses

### default

接口响应，业务状态见下方详细说明。

#### Example

```json
{
  "status": true,
  "msg": "文件已保存!",
  "historys": [
    "1779514192"
  ],
  "st_mtime": "1779514192"
}
```

- `action132.response.default.status` (boolean, optional) — `true` 保存成功
- `action132.response.default.msg` (string, optional) — `文件已保存!`
- `action132.response.default.historys` (array<unknown>, optional) — 历史版本 ID 列表
- `action132.response.default.st_mtime` (string, optional) — 修改时间戳


## SaveFileBody

保存文本内容到指定文件，用于在线编辑代码或配置文件。

- **路由**：`POST /files`
- **action**：`SaveFileBody`

## 输入参数

| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| action | 是 | String | 固定值 `SaveFileBody` |
| path | 是 | String | 文件绝对路径 |
| data | 是 | String | 要写入的文件内容 |
| encoding | 是 | String | 文件编码：`utf-8` / `ascii` / `ansi` / `GBK` / `BIG5` |

> **重要**：`encoding` 参数必须传入，否则会报 `FILE_SAVE_ERR` 错误。

## 输出参数

| 参数名称 | 类型 | 描述 |
|----------|------|------|
| status | Boolean | `true` 保存成功 |
| msg | String | `文件已保存!` |
| historys | Array | 历史版本 ID 列表 |
| st_mtime | String | 修改时间戳 |

## 示例

### 请求

```
POST /files HTTP/1.1
Host: 192.168.168.213:8888
Content-Type: application/x-www-form-urlencoded

action=SaveFileBody&path=/tmp/test.txt&data=hello world&encoding=utf-8
```

### 响应

```json
{"status": true, "msg": "文件已保存!", "historys": ["1779514192"], "st_mtime": "1779514192"}
```

## 相关接口

- [GetFileBody](/api/files/getfilebody) — 读取文件
- [CreateFile](/api/files/createfile) — 创建文件

