支持图片 / 视频 / 音频 / 安装包 / 文档等多种格式。生产环境中请始终由业务后端持有密钥并计算签名,切勿在浏览器端暴露 AppSecret。
暂无上传记录。
统一接口 POST /api/v1/upload,表单字段 file,
需携带 X-App-Key、X-Timestamp、
X-Nonce、X-Signature
待签名字符串(用 \n 换行拼接):
METHOD \n PATH \n TIMESTAMP \n NONCE \n SHA256(文件内容)
$file = 'a.jpg'; // 也支持 mp4 / apk 等任意已授权格式
$key = '你的 AppKey';
$secret = '你的 AppSecret';
$path = '/api/v1/upload';
$ts = time();
$nonce = bin2hex(random_bytes(8));
$signStr = implode("\n", ['POST', $path, $ts, $nonce, hash_file('sha256', $file)]);
$sig = hash_hmac('sha256', $signStr, $secret);
$ch = curl_init('https://你的域名' . $path);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["X-App-Key: $key", "X-Timestamp: $ts",
"X-Nonce: $nonce", "X-Signature: $sig"],
CURLOPT_POSTFIELDS => ['file' => new CURLFile($file)],
]);
echo curl_exec($ch); // {"code":0,"data":{"url":"https://.../image/2026-09-12/1/xx.jpg"}}
import hashlib, hmac, time, uuid, requests
key, secret = 'AppKey', 'AppSecret'
content = open('demo.mp4', 'rb').read()
ts, nonce = str(int(time())), uuid.uuid4().hex
sign_str = '\n'.join(['POST', '/api/v1/upload', ts, nonce,
hashlib.sha256(content).hexdigest()])
sig = hmac.new(secret.encode(), sign_str.encode(), hashlib.sha256).hexdigest()
r = requests.post('https://你的域名/api/v1/upload',
files={'file': ('demo.mp4', content)},
headers={'X-App-Key': key, 'X-Timestamp': ts,
'X-Nonce': nonce, 'X-Signature': sig})
print(r.json())