欢迎使用我们的公共图片上传 API。您可以通过编程方式将图片上传到本站。
所有API请求都应发送到以下URL:
POST /api/v1.php
请求体必须使用 multipart/form-data
格式进行编码。
参数名 | 类型 | 必需 | 描述 |
---|---|---|---|
image |
File | 是 | 要上传的图片文件。支持的格式包括:jpg, png, webp, bmp, tiff, avif, gif。 |
outputFormat | String | 否 | 输出格式(auto , jpeg , png , webp , gif , webp_animated ),默认为 auto 。webp : 输出静态WebP。如果输入是动图,则只转换第一帧。gif : 输出优化后的GIF动图。webp_animated : 输出动态WebP。为了获得更好的压缩率和显示效果,我们强烈建议将静态图片转换为 webp ,将动态图片转换为 webp_animated 。
|
password_enabled |
String | 否 | 设为 "true" 以启用密码保护。必须与 image_password 参数一同使用。 |
image_password |
String | 否 | 为图片设置的访问密码。当 password_enabled 为 "true" 时此项为必需。 |
API 的响应将采用 JSON 格式。
{
"success": true,
"url": "https://img.scdn.io/i/6640c49c7161b_1715519644.webp",
"data": {
"filename": "6640c49c7161b_1715519644.webp",
"original_size": 102400,
"compressed_size": 20480,
"compression_ratio": 80
}
}
{
"success": true,
"url": "https://img.scdn.io/p/unique_encrypted_id_string.webp"
}
{
"success": true,
"url": "https://img.scdn.io/i/existing_image_name.webp",
"message": "图片已存在,秒传成功!"
}
{
"success": false,
"message": "请求过于频繁,请稍后再试。"
}
上传公开图片:
curl -X POST -F "image=@/path/to/your/image.jpg" https://img.scdn.io/api/v1.php
将GIF动图转换为WebP动图:
curl -X POST \
-F "image=@/path/to/your/animation.gif" \
-F "outputFormat=webp_animated" \
https://img.scdn.io/api/v1.php
上传加密图片:
curl -X POST \
-F "image=@/path/to/your/image.jpg" \
-F "password_enabled=true" \
-F "image_password=your_secret_password" \
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 |
服务器内部发生错误,例如数据库连接失败、压缩失败等。 |