上传 API
上传 API
干净的 HTTP 上传接口 + Bearer API Token,便于脚本、PicGo、CI。
创建 Token
登录 → 设置 → API Token → 新建。
Scope 选 upload(仅上传)或 full。
明文只显示一次,请立即保存到密码管理器。
上传
curl -X POST https://your-host/api/v1/upload \
-H "Authorization: Bearer <API_TOKEN>" \
-F file=@shot.png \
-F visibility=public
| 项 | 值 |
|---|---|
| Method | POST |
| Content-Type | multipart/form-data |
| 文件字段名 | file(必须) |
| 鉴权 | Authorization: Bearer <token> |
| 可选表单 | visibility=public | private(默认随用户偏好) |
成功响应(节选)
{
"status": true,
"message": "ok",
"data": {
"key": "xxxxxxxxxxxx",
"name": "shot.png",
"instant": false,
"links": {
"url": "https://your-host/i/xxxxxxxxxxxx.png",
"markdown": "",
"html": "<img src=\"https://your-host/i/xxxxxxxxxxxx.png\" alt=\"shot.png\">",
"bbcode": "[img]https://your-host/i/xxxxxxxxxxxx.png[/img]",
"thumbnail_url": "https://your-host/t/xxxxxxxxxxxx.jpg"
}
}
}
取直链:JSON Path data.links.url。
常见错误
| HTTP | 含义 |
|---|---|
| 401 | Token 无效 / 未带 Bearer |
| 403 | 游客上传关闭且未登录(或无权限) |
| 413 | 超过用户组大小上限 |
| 415 | 扩展名不允许 |
| 429 | 限速(关注 Retry-After) |
无 Token 游客上传
同一 URL 可不带 Authorization,但受游客组策略约束(限速、是否开启)。
不要给常驻图床工具配游客模式。
自测清单
export IMGLI_TOKEN='你的 token'
curl -sS -X POST "https://your-host/api/v1/upload" \
-H "Authorization: Bearer $IMGLI_TOKEN" \
-F 'file=@/path/to/test.png' \
-F 'visibility=public' | jq .
# 浏览器打开 data.links.url
压测脚本(仓库):scripts/loadtest.py write --token …
健康检查示例:deploy/ops/health-check.sh