API
สี่เอนด์พอยต์: ขอ URL สำหรับอัปโหลด สร้างงานขยาย ตรวจผลลัพธ์ และลองงานที่ล้มเหลวใหม่ พร้อมกฎของพารามิเตอร์ สถานะงาน และข้อผิดพลาด
POST
API อัปโหลดรูปภาพ
/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 ได้
- เรียก endpoint นี้ด้วย API key เพื่อรับ URL อัปโหลด R2 ชั่วคราวและ URL รูปภาพสาธารณะ
- อัปโหลดไฟล์ด้วย PUT โดยใช้ Content-Type เดิม จากนั้นใช้ fileurl เป็น input ใน API ขยายภาพ
- URL หลัก:
https://bigjpg.com
POST
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
- style สามารถเป็น ’art', 'photo' ซึ่งหมายถึง 'ภาพวาด', 'ภาพถ่าย'
- noise สามารถเป็น ’-1', '0', '1', '2', '3' ซึ่งหมายถึง 'ไม่มี', 'น้อย', 'ปานกลาง', 'สูง', 'สูงสุด'
- x2 สามารถเป็น ’1', '2', '3', '4' ซึ่งหมายถึง 2x, 4x, 8x, 16x
- ป้อน URL ภาพที่ต้องการขยาย
- เรียกสำเร็จจะได้ tid (id ของงาน), minute (เวลาที่คาดไว้) และ remaining_api_calls (จำนวนครั้งที่เหลือ)
GET
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())
- ส่ง id ของงานได้หลายตัวคั่นด้วยจุลภาค สูงสุด 100 ตัวต่อหนึ่งคำขอ
- แต่ละงานจะคืนค่าเป็น {"status": ..., "url": ..., "size": ...} โดย status มี new, process, success และ error
- url กับ size จะยังว่างจนกว่างานจะเสร็จ
POST
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())
การตอบกลับข้อผิดพลาด
status
- valid_api_key_required — ไม่มีหรือไม่รู้จักเฮดเดอร์ X-API-KEY ตรวจชื่อเฮดเดอร์และดูว่าคีย์เป็นของบัญชีเสียเงินที่ยังไม่หมดอายุ
- requires_vip — บัญชีเป็นแบบฟรีหรือหมดอายุแล้ว API ต้องใช้แพ็กเกจเสียเงินที่ยังใช้งานได้
- month_limit — โควตา API ของเดือนนี้ใช้หมดแล้ว ทุกครั้งที่เรียกสำเร็จจะคืน remaining_api_calls จึงดูล่วงหน้าได้
- param_error — พารามิเตอร์อยู่นอกช่วง: style ต้องเป็น art หรือ photo, noise ตั้งแต่ -1 ถึง 3, x2 ตั้งแต่ 1 ถึง 4 (บัญชีฟรี 1 ถึง 2)
- input_url_error — input ต้องเป็น URL รูปภาพ http:// หรือ https:// ที่เข้าถึงได้จากสาธารณะ
X-API-KEY: สมาชิกแบบชำระเงินสามารถใช้ API ได้
ติดต่อเราได้ที่ i@bigjpg.com สำหรับการเรียก API เพิ่มเติม