Skip to content
Console

S4 object storage API

Query an S4 bucket's capacity and file count, plus real-time access logs for the last 3 days.

Uploading, downloading, and listing files don't go through this API. Use an S3 SDK.

Authentication

Every endpoint is authenticated with the Authorization request header, whose value is your console API token (no Bearer prefix). Get one at Console › API Token. For details, see API tokens.

curl -H "Authorization: <API Token>" \
  "https://api.bitiful.com/s4/data/<bucket-name>/usage"

An API token can access the resources in your account. Use it on the server only, and never put it in frontend code or a public repository.

Base URL

https://api.bitiful.com

Error format

When a request fails, the matching HTTP status code and JSON are returned, and message is the error description:

{"message":"鉴权失败"}
Status codeMeaningWhat to do
401The token is missing or invalidCheck the request header, confirm there's no Bearer, and that the token hasn't been deleted
403An invalid parameter, the bucket doesn't belong to the current account, the query time is out of range, or the account is restrictedFix it according to message
500Server errorTry again later

Example: query capacity

curl -H "Authorization: <API Token>" \
  "https://api.bitiful.com/s4/data/my-bucket/usage"

Capacity is in bytes. tmp_* are temporary files produced by multipart uploads, and they're also counted in total_*.

Example: pull recent error logs

curl -G "https://api.bitiful.com/s4/data/my-bucket/logs" \
  -H "Authorization: <API Token>" \
  --data-urlencode "start_time=$(date +%s)000000000" \
  --data-urlencode "codes=4XX,5XX" \
  --data-urlencode "limit=100"

start_time is the time upper bound and is required. Logs are returned from newest to oldest, and each one is earlier than start_time.

Example: page through all logs

logs.py
import time
import requests

URL = "https://api.bitiful.com/s4/data/my-bucket/logs"
HEADERS = {"Authorization": "<API Token>"}

cursor = time.time_ns()                        # Page backward from now
oldest = cursor - 3 * 24 * 3600 * 10**9        # Only the last 3 days can be queried

while cursor > oldest:
    resp = requests.get(URL, headers=HEADERS, params={"start_time": cursor, "limit": 1000}, timeout=60)
    resp.raise_for_status()
    logs = resp.json()["data"]
    if not logs:
        break
    for log in logs:
        print(log["access_time"], log["code"], log["method"], log["path"])
    cursor = logs[-1]["access_time"]           # The last entry is the earliest on this page

access_time is an integer in nanoseconds, about 1.8 × 10^18, which exceeds the exact range of a JavaScript Number. When paging in JavaScript, use a JSON parser that supports big integers, or handle it with BigInt.

对象存储

GET容量与文件数/s4/data/{bucket}/usage
GET实时日志/s4/data/{bucket}/logs