API
Quatro endpoints: pedir uma URL de upload, criar a tarefa, consultar o resultado e repetir uma tarefa falhada. Com regras de parâmetros, estados e erros.
POST
API de upload de imagens
/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
- Membros pagos podem usar a API
- Chame este endpoint com sua chave de API para obter uma URL temporária de upload no R2 e a URL pública da imagem
- Envie o arquivo com PUT usando o mesmo Content-Type e use fileurl como input na API de ampliação
- URL base:
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
- Uma chamada bem-sucedida retorna tid (id da tarefa), minute (tempo estimado) e remaining_api_calls (chamadas restantes).
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())
- Você pode passar vários ids separados por vírgula — até 100 por requisição.
- Cada tarefa volta como {"status": ..., "url": ..., "size": ...}; status é new, process, success ou error.
- url e size ficam vazios até a tarefa terminar.
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())
Respostas de erro
status
- valid_api_key_required — o cabeçalho X-API-KEY está ausente ou não é reconhecido. Confira o nome do cabeçalho e se a chave pertence a uma conta paga ativa.
- requires_vip — a conta é gratuita ou expirou. A API exige um plano pago ativo.
- month_limit — a cota mensal acabou. Toda chamada bem-sucedida retorna remaining_api_calls, então dá para acompanhar antes de zerar.
- param_error — parâmetros fora da faixa: style precisa ser art ou photo, noise de -1 a 3 e x2 de 1 a 4 (contas gratuitas, 1 a 2).
- input_url_error — input deve ser uma URL de imagem http:// ou https:// acessível publicamente.
X-API-KEY: Membros pagos podem usar a API
Contate-nos i@bigjpg.com para mais chamadas API