Base64 File Upload
curl --request POST \
--url https://api.aihubmax.com/v1/files/upload/base64 \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"file_data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk...",
"file_name": "photo.png",
"auto_cleanup": true
}
'import requests
url = "https://api.aihubmax.com/v1/files/upload/base64"
payload = {
"file_data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk...",
"file_name": "photo.png",
"auto_cleanup": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
file_data: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk...',
file_name: 'photo.png',
auto_cleanup: true
})
};
fetch('https://api.aihubmax.com/v1/files/upload/base64', 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://api.aihubmax.com/v1/files/upload/base64",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'file_data' => 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk...',
'file_name' => 'photo.png',
'auto_cleanup' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://api.aihubmax.com/v1/files/upload/base64"
payload := strings.NewReader("{\n \"file_data\": \"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk...\",\n \"file_name\": \"photo.png\",\n \"auto_cleanup\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.aihubmax.com/v1/files/upload/base64")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"file_data\": \"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk...\",\n \"file_name\": \"photo.png\",\n \"auto_cleanup\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.aihubmax.com/v1/files/upload/base64")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"file_data\": \"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk...\",\n \"file_name\": \"photo.png\",\n \"auto_cleanup\": true\n}"
response = http.request(request)
puts response.read_body{
"id": "file-1757165031-a1b2c3",
"filename": "photo.png",
"url": "https://cdn.foxapi.cc/uploads/20260319/a1b2c3d4e5f6/photo.png",
"size": 204800,
"created": 1757165031
}{
"error": {
"message": "请求参数无效",
"type": "invalid_request_error"
}
}{
"error": {
"message": "API密钥无效",
"type": "authentication_error"
}
}{
"error": {
"message": "存储空间不足",
"type": "permission_error"
}
}{
"error": {
"message": "文件过大",
"type": "file_too_large_error"
}
}{
"error": {
"message": "请求频率超限",
"type": "rate_limit_error"
}
}{
"error": {
"message": "服务器内部错误",
"type": "server_error"
}
}文件上传
Base64 文件上传
- 支持 Base64 编码和 Data URL 格式
- 可自动识别文件类型并分类存储
- 返回可访问的文件 URL
- 文件会在 72 小时后过期
- 存储空间不足时默认自动清理最早上传的文件(可通过 auto_cleanup=false 关闭)
POST
/
v1
/
files
/
upload
/
base64
Base64 File Upload
curl --request POST \
--url https://api.aihubmax.com/v1/files/upload/base64 \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"file_data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk...",
"file_name": "photo.png",
"auto_cleanup": true
}
'import requests
url = "https://api.aihubmax.com/v1/files/upload/base64"
payload = {
"file_data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk...",
"file_name": "photo.png",
"auto_cleanup": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
file_data: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk...',
file_name: 'photo.png',
auto_cleanup: true
})
};
fetch('https://api.aihubmax.com/v1/files/upload/base64', 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://api.aihubmax.com/v1/files/upload/base64",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'file_data' => 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk...',
'file_name' => 'photo.png',
'auto_cleanup' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://api.aihubmax.com/v1/files/upload/base64"
payload := strings.NewReader("{\n \"file_data\": \"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk...\",\n \"file_name\": \"photo.png\",\n \"auto_cleanup\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.aihubmax.com/v1/files/upload/base64")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"file_data\": \"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk...\",\n \"file_name\": \"photo.png\",\n \"auto_cleanup\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.aihubmax.com/v1/files/upload/base64")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"file_data\": \"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk...\",\n \"file_name\": \"photo.png\",\n \"auto_cleanup\": true\n}"
response = http.request(request)
puts response.read_body{
"id": "file-1757165031-a1b2c3",
"filename": "photo.png",
"url": "https://cdn.foxapi.cc/uploads/20260319/a1b2c3d4e5f6/photo.png",
"size": 204800,
"created": 1757165031
}{
"error": {
"message": "请求参数无效",
"type": "invalid_request_error"
}
}{
"error": {
"message": "API密钥无效",
"type": "authentication_error"
}
}{
"error": {
"message": "存储空间不足",
"type": "permission_error"
}
}{
"error": {
"message": "文件过大",
"type": "file_too_large_error"
}
}{
"error": {
"message": "请求频率超限",
"type": "rate_limit_error"
}
}{
"error": {
"message": "服务器内部错误",
"type": "server_error"
}
}授权
所有接口均需要使用Bearer Token进行认证
使用时在请求头中添加:
Authorization: Bearer YOUR_API_KEY
请求体
application/json
Base64 编码的文件内容,支持纯 base64 或 data URL 格式
示例:
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk..."
文件名(含扩展名),不提供时从 data URL MIME 推断或默认 upload.bin
示例:
"photo.png"
存储空间不足时是否自动清理最早上传的文件以腾出空间
说明:
- 默认
true:自动淘汰最早上传的文件 - 设为
false:空间不足时直接返回 403 错误
示例:
true
⌘I