API
Bốn endpoint: xin URL tải lên, tạo tác vụ phóng to, kiểm tra kết quả, thử lại tác vụ lỗi. Kèm quy tắc tham số, trạng thái tác vụ và lỗi trả về.
POST
API tải ảnh lên
/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
- Thành viên trả phí có thể sử dụng API
- Gọi endpoint này bằng API key để nhận URL tải lên R2 tạm thời và URL hình ảnh công khai
- Tải tệp lên bằng PUT với cùng Content-Type, sau đó dùng fileurl làm input trong API phóng to
- URL gốc:
https://bigjpg.com
POST
Enlarge API
/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 format
- style can be 'art', 'photo' which means 'cartoon illustration', 'photo'
- noise can be '-1', '0', '1', '2', '3' which means 'None', 'Low, 'Medium', 'High', 'Highest'
- x2 can be '1', '2', '3', '4' which means 2x, 4x, 8x, 16x
- input your enlarge image url
- Gọi thành công trả về tid (id tác vụ), minute (thời gian dự kiến) và remaining_api_calls (số lượt còn lại).
GET
Result Query API
/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())
- Có thể truyền nhiều id tác vụ cách nhau bằng dấu phẩy — tối đa 100 mỗi lần gọi.
- Mỗi tác vụ trả về {"status": ..., "url": ..., "size": ...}; status là new, process, success hoặc error.
- url và size vẫn trống cho đến khi tác vụ xong.
POST
Task retry API
/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())
Phản hồi lỗi
status
- valid_api_key_required — thiếu hoặc không nhận ra header X-API-KEY. Kiểm tra tên header và xem khóa có thuộc tài khoản trả phí còn hạn không.
- requires_vip — tài khoản đang miễn phí hoặc đã hết hạn. API cần gói trả phí còn hiệu lực.
- month_limit — đã dùng hết hạn mức trong tháng. Mỗi lần gọi thành công đều trả về remaining_api_calls nên có thể theo dõi trước.
- param_error — tham số ngoài khoảng cho phép: style phải là art hoặc photo, noise từ -1 đến 3, x2 từ 1 đến 4 (tài khoản miễn phí 1 đến 2).
- input_url_error — input phải là URL ảnh http:// hoặc https:// truy cập công khai.
X-API-KEY: Thành viên trả phí có thể sử dụng API
Liên hệ với chúng tôi theo i@bigjpg.com để biết thêm các lệnh gọi API