公共上传 API 文档

欢迎使用我们的公共图片上传 API。您可以通过编程方式将图片上传到本站。

API 端点

所有API请求都应发送到以下URL:

POST /api/v1.php

请求体必须使用 multipart/form-data 格式进行编码。

请求参数
参数名 类型 必需 描述
image File 要上传的图片文件。支持的格式包括:jpg, png, webp, bmp, tiff, avif。
outputFormat String 输出格式(auto, jpeg, png, webp),默认为 auto
为了获得更好的压缩率和显示效果,我们强烈建议使用 webpauto 格式。
响应格式

API 的响应将采用 JSON 格式。

成功响应示例:
{
  "success": true,
  "url": "https://img.scdn.io/i/6640c49c7161b_1715519644.webp",
  "delete_url": "https://img.scdn.io/delete/6640c49c7161b_1715519644.webp/b73289937398187a53ace3957294c1d5",
  "message": "秒传成功!"
}
失败响应示例:
{
  "success": false,
  "message": "请求过于频繁,请稍后再试。"
}
代码示例
curl -X POST -F "image=@/path/to/your/image.jpg" https://img.scdn.io/api/v1.php
const fileInput = document.querySelector('input[type="file"]');
const formData = new FormData();
formData.append('image', fileInput.files[0]);

fetch('https://img.scdn.io/api/v1.php', {
  method: 'POST',
  body: formData
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
import requests

url = 'https://img.scdn.io/api/v1.php'
file_path = '/path/to/your/image.jpg'

with open(file_path, 'rb') as f:
    files = {'image': f}
    response = requests.post(url, files=files)

print(response.json())
<?php
$url = 'https://img.scdn.io/api/v1.php';
$filePath = '/path/to/your/image.jpg'; // 请替换为实际的文件路径

if (!file_exists($filePath)) {
    die('错误: 文件不存在。');
}

// 推荐使用 CURLFile class 处理文件上传
$cfile = new CURLFile($filePath, mime_content_type($filePath), basename($filePath));

$postData = [
    'image' => $cfile,
];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
// 如果您的服务器需要SSL验证,请取消注释下一行
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'cURL 错误: ' . curl_error($ch);
} else {
    // 打印原始JSON响应
    header('Content-Type: application/json');
    echo $response;
}

curl_close($ch);
?>
错误码
状态码 描述
400 Bad Request 没有上传文件,或者上传过程中发生错误,或者文件格式不被支持。
405 Method Not Allowed 使用了非 POST 请求方法。
429 Too Many Requests 请求过于频繁。默认限制为5秒内1次请求。
500 Internal Server Error 服务器内部发生错误,例如数据库连接失败、压缩失败等。