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

# 完成文件上传

> 完成文件上传过程并验证上传的JSON文件。此端点验证文件是否存在，验证其JSON格式，并将文件状态更新为已完成。

## 完成文件上传

在上传文件后，你需要调用此端点来完成上传过程。此操作将验证文件是否存在，检查其JSON格式是否有效，并将文件状态更新为已完成。

### 请求

**方法**: `POST`

**路径**: `/v1/files/{file_id}/complete`

#### 路径参数

* `file_id`: 要完成上传的文件的唯一标识符。

### 响应

成功调用此端点后，你将收到一个确认响应，表示文件上传已成功完成。

### 示例

```jsx theme={null}
import { useState } from 'react';
import { completeFileUpload } from 'olostep-sdk';

function CompleteUploadButton({ fileId }) {
  const [status, setStatus] = useState('pending');

  const handleCompleteUpload = async () => {
    try {
      await completeFileUpload(fileId);
      setStatus('completed');
    } catch (error) {
      setStatus('error');
    }
  };

  return (
    <button onClick={handleCompleteUpload}>
      {status === 'pending' ? '完成上传' : status === 'completed' ? '上传完成' : '上传失败'}
    </button>
  );
}
```

### 注意事项

* 确保在调用此端点之前，文件已完全上传。
* 验证文件的JSON格式，以避免格式错误导致的上传失败。


## OpenAPI

````yaml zh/openapi/files.json POST /v1/files/{file_id}/complete
openapi: 3.0.3
info:
  title: 文件 API
  version: 1.0.0
servers:
  - url: https://api.olostep.com
security: []
paths:
  /v1/files/{file_id}/complete:
    post:
      summary: 完成文件上传
      description: >-
        完成文件上传过程并验证上传的JSON文件。此端点验证文件是否存在，验证其JSON格式，检查文件大小（最大200MB），并将文件状态更新为completed。
      parameters:
        - name: file_id
          in: path
          required: true
          description: 要完成的文件的唯一标识符。
          schema:
            type: string
      responses:
        '200':
          description: 文件上传成功完成。
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: 文件 ID
                  object:
                    type: string
                    description: 对象类型。此端点为 "file"。
                  created:
                    type: integer
                    description: 创建的纪元时间戳
                  filename:
                    type: string
                    description: 上传文件的文件名
                  bytes:
                    type: integer
                    description: 文件大小（字节）
                  purpose:
                    type: string
                    description: 文件的用途
                  status:
                    type: string
                    description: 文件状态。成功完成后将为 "completed"。
        '400':
          description: 错误请求。文件已完成、状态无效、文件过大（最大200MB）或JSON格式无效。
        '401':
          description: 无效的 API 密钥
        '404':
          description: 文件未找到或文件未上传到S3
        '500':
          description: 内部服务器错误
      security:
        - Authorization: []
components:
  securitySchemes:
    Authorization:
      type: http
      scheme: bearer
      description: Bearer认证头格式为Bearer <token>，其中<token>是你的认证令牌。

````