API
四个接口:申请上传地址、创建放大任务、查询结果、失败重试。包含参数规则、任务状态和错误返回。
POST
图片上传接口
/api/img_upload
cURL
curl -X POST https://bigjpg.com/api/img_upload \
-H 'X-API-KEY: YOUR_API_KEY' \
-d 'filename=small.jpg' \
-d 'filetype=image/jpeg'
# Use url from the response to upload the file to R2.
curl -X PUT --upload-file small.jpg \
-H 'Content-Type: image/jpeg' \
'UPLOAD_URL'
Python
import requests
filename = 'small.jpg'
filetype = 'image/jpeg'
r = requests.post(
url='https://bigjpg.com/api/img_upload',
headers={'X-API-KEY': 'YOUR_API_KEY'},
data={'filename': filename, 'filetype': filetype}
)
upload = r.json()
with open(filename, 'rb') as image:
requests.put(
url=upload['url'],
data=image,
headers={'Content-Type': filetype}
)
print(upload['fileurl']) # use as input in the enlarge API
- 付费会员可以调用 API
- 携带 API Key 调用此接口,获取临时 R2 上传地址和图片公开地址
- 使用相同的 Content-Type 通过 PUT 上传文件,再将 fileurl 作为放大接口的 input
- 接口地址:
https://bigjpg.com
POST
放大图片接口
/api/task/
cURL
curl -d '{"style": "art", "noise": "3", "x2": "1", "input": "YOUR_IMAGE_URL"}' \
-H 'X-API-KEY: YOUR_API_KEY' \
https://bigjpg.com/api/task/
Python
import json
import requests
data = {
'style': 'art',
'noise': '3',
'x2': '1',
'file_name': 'small.jpg',
'input': 'YOUR_IMAGE_URL'
}
r = requests.post(
url='https://bigjpg.com/api/task/',
headers={'X-API-KEY': 'YOUR_API_KEY'},
data=json.dumps(data)
)
print(r.json())
- 参数是 JSON 格式
- style 参数有 'art', 'photo' 分别表示 '卡通插画', '照片'
- noise 参数有 '-1', '0', '1', '2', '3' 分别表示降噪程度 '无', '低', '中', '高', '最高'
- x2 参数有 '1', '2', '3', '4' 分别表示 2x, 4x, 8x, 16x
- input 参数是需要放大的图片链接
- 创建成功会返回 tid(任务 id)、minute(预估时间)和 remaining_api_calls(剩余调用次数)。
GET
放大结果查询接口
/api/task/{task_ids}
cURL
curl https://bigjpg.com/api/task/tid1,tid2,tid3,tid100
Python
import requests
r = requests.get(
url='https://bigjpg.com/api/task/tid1,tid2,tid3,tid100'
)
print(r.json())
- 一次可以查多个任务,用英文逗号分隔,单次最多 100 个。
- 每个任务返回 {"status": ..., "url": ..., "size": ...},status 有 new、process、success、error 四种。
- 任务成功之前,url 和 size 都是空的。
POST
任务重试接口
/api/task/{task_ids}
cURL
curl -X POST https://bigjpg.com/api/task/tid1,tid2,tid3,tid100
Python
import requests
r = requests.post(
url='https://bigjpg.com/api/task/tid1,tid2,tid3,tid100'
)
print(r.json())
错误返回
status
- valid_api_key_required —— 请求头里的 X-API-KEY 缺失或无法识别。先确认字段名没写错,再看这个 key 是否属于尚未过期的付费账号。
- requires_vip —— 账号是免费版或已经到期。API 只对有效期内的付费账号开放。
- month_limit —— 当月接口调用次数已经用完。每次成功创建任务都会返回 remaining_api_calls,可以提前盯着这个数字。
- param_error —— 参数超出范围:style 只能是 art 或 photo,noise 取 -1 到 3,x2 取 1 到 4(免费账号 1 到 2)。
- input_url_error —— input 必须是外网可访问的 http:// 或 https:// 图片地址。
X-API-KEY: 付费会员可以调用 API
可通过邮件 i@bigjpg.com 联系客服,单独购买更多 API 接口调用次数