跳转到主要内容
POST
/
files
文件上传接口
curl --request POST \
  --url https://geekai.co/api/v1/files \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: multipart/form-data' \
  --form file='@example-file' \
  --form purpose=file-url \
  --form format=text
import requests

url = "https://geekai.co/api/v1/files"

files = { "file": ("example-file", open("example-file", "rb")) }
payload = {
"purpose": "file-url",
"format": "text"
}
headers = {"Authorization": "Bearer <token>"}

response = requests.post(url, data=payload, files=files, headers=headers)

print(response.text)
const form = new FormData();
form.append('file', '@/E:/文档/test.pdf');
form.append('purpose', 'file-url');
form.append('format', 'text');

const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

options.body = form;

fetch('https://geekai.co/api/v1/files', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://geekai.co/api/v1/files",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n@/E:/文档/test.pdf\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\nfile-url\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\n\r\ntext\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://geekai.co/api/v1/files"

payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n@/E:/文档/test.pdf\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\nfile-url\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\n\r\ntext\r\n-----011000010111000001101001--")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://geekai.co/api/v1/files")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n@/E:/文档/test.pdf\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\nfile-url\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\n\r\ntext\r\n-----011000010111000001101001--")
.asString();
require 'uri'
require 'net/http'

url = URI("https://geekai.co/api/v1/files")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n@/E:/文档/test.pdf\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\nfile-url\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\n\r\ntext\r\n-----011000010111000001101001--"

response = http.request(request)
puts response.read_body
{
  "uuid": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "name": "<string>",
  "size": 123,
  "type": "<string>",
  "md5": "<string>",
  "url": "<string>",
  "content": "<string>"
}
{
"code": "invalid_file",
"message": "不支持的文件格式"
}
{
"code": "unauthorized",
"message": "Invalid API key or token"
}
{
"code": "file_too_large",
"message": "文件大小超过50MB限制"
}
{
"code": "unsupported_media_type",
"message": "不支持的文件类型"
}
{
"code": "invalid_request",
"message": "请求参数不合法"
}
极客智坊提供了文件上传与内容提取功能,支持多种文件格式,包括.PDF .DOCX .DOC .XLS .XLSX .PPT .PPTX .PNG .JPG .JPEG .CSV .PY .TXT .MD .BMP .GIF等,你可以通过上传文件接口上传待识别文件,然后通过文件内容提取接口获取文件内容,借助该基础服务,你可以完成AI文件对话/RAG等上层业务场景的功能实现。

cURL 请求示例

curl --location --request POST 'https://geekai.co/api/v1/files' \
--header 'Authorization: Bearer {$GEEKAI_API_KEY}' \
--form 'file=@"/E:/文档/geekai/test.pdf"'
--form 'purpose="file-extract"'

Postman 请求响应示例

上传文件

授权

Authorization
string
header
必填

API认证token

请求体

multipart/form-data
file
file
必填

上传的文件,目前支持PDF/DOCX/XLSX/PPTX/PNG/JPG/JPEG/CSV/TXT/MD/MP3/MP4等格式

purpose
enum<string>
默认值:file-url

上传目的,目前仅支持获取文件URL、文件内容提取

可用选项:
file-url,
file-extract
format
string
默认值:text

返回文件内容格式,目前仅支持文本格式

示例:

"text"

响应

成功响应

uuid
string<uuid>
必填

文件唯一ID,可通过该ID获取文件内容

status
enum<string>
必填

文件状态: pending(待处理)/reading(读取中)/failed(读取失败)/done(已读取)

可用选项:
pending,
reading,
processing,
failed,
done
name
string

文件名称

size
integer

文件大小

type
string

文件MIME类型

md5
string

文件MD5值

url
string

文件URL地址

content
string

文件内容(只有status=done时,才会填充该字段)