B7RDevelopers
ReferenceFiles
Reference / Files

Files

View .md

A request body is JSON of at most 256 KB, so a file never travels in it. Three steps instead: ask B7R for an upload with POST /v1/uploads, PUT the file to the address it answers, then send the upload's upload_id in the call that uses the file.

  • The address is on B7R's own storage in Saudi Arabia. It takes one PUT of the whole file, with the content-type header the answer gives; a second PUT to it is refused.
  • B7R reads the file back and decides its type from its bytes and its size from its length. A file whose bytes are not the type you declared, or whose length is not size_bytes, is refused by the call that uses it.
  • Two deadlines. Start the PUT before upload.expires_at, when the address expires: it can be about a minute, so send the file right after you have the answer (a late PUT is refused; ask again). Use the upload by expires_at, an hour after you asked. An upload is used once, and deleted three hours after you asked whether it was used or not.
  • The answer is never stored: a lost answer cannot be read again. Ask again; the first upload is never used and is deleted with the rest.
  • An upload is used up by the call that saves it (a product create or change). A call refused or cut off before it saves leaves the upload usable, so a retry can name it again until expires_at.
  • Each upload counts against your uploads an hour, uploads_per_hour in GET /v1/me?include=limits. Past it the answer is 429 rate_limited with Retry-After. When B7R holds too many uploads from every account together, the answer is 503 service_unavailable with Retry-After: try again then.

Ask for an upload

POST/v1/uploads

Any key may call it, but each purpose needs its own area of the key (the table below): without it the answer is 403 area_forbidden naming the area, before anything is made. A purpose is taken from the day its feature is live; before that it answers 400 invalid_request with invalid_value on purpose.

The type and size must be ones the purpose takes, or the answer is 400 invalid_request naming content_type (with the types it takes in valid_values) or size_bytes.

Headers

Authorizationstringrequired

Bearer b7r_live_.... Any valid key. X-B7R-Key works too; send one, never both.

Idempotency-Keystringrequired

A new value per operation (up to 255 letters, digits, ., _, : or -; a UUID works), the same value on its retries. See Safe retries.

Content-Typestringrequired

application/json, when the request has a body.

Accept-Languagestring

ar for Arabic error titles; anything else gives English. Codes never change.

Body

purposestringrequired

What the file is for. Each purpose needs its own area of the key, and is taken only once its release is live. One of design, design_original, my_store_image, ticket_image, avatar, brand_logo.

content_typestringrequired

What the file is. B7R reads the file back and decides its type from its bytes; a file of another type is refused when it is used. One of image/png, image/jpeg, image/webp, application/pdf.

size_bytesintegerrequired

The file's exact size in bytes. A file of another size is refused when it is used. At most 26214400.

Answer

upload_idstring (uuid)required

Name it in the call that uses the file.

uploadobjectrequired
Child fields
methodconstantrequired

Always "PUT".

urlstring (uri)required

Send the file here once, as the whole request body. The address works for one PUT and is never shown again.

headersobjectrequired
Child fields
content-typestringrequired

The content type you declared. One of image/png, image/jpeg, image/webp, application/pdf.

expires_atstringrequired

Start the PUT before this time: the address expires then. It is short (about a minute): PUT the file right after you have the answer.

expires_atstringrequired

Use the upload by this time, an hour after you asked: name its upload_id in the call that uses the file before then. After it the upload is never used and is deleted.

Errors

Request
curl -X POST https://api.b7r.app/v1/uploads \
  -H "Authorization: Bearer $B7R_API_KEY" \
  -H "Idempotency-Key: $(uuidgen 2>/dev/null || node -e 'console.log(crypto.randomUUID())')" \
  -H "Content-Type: application/json" \
  -d '{
    "purpose": "design",
    "content_type": "image/png",
    "size_bytes": 1843200
  }'
const res = await fetch("https://api.b7r.app/v1/uploads", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.B7R_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "purpose": "design",
    "content_type": "image/png",
    "size_bytes": 1843200
  }),
});
const data = await res.json();
import os, requests, uuid

res = requests.post(
    "https://api.b7r.app/v1/uploads",
    headers={
        "Authorization": f"Bearer {os.environ['B7R_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "purpose": "design",
        "content_type": "image/png",
        "size_bytes": 1843200
    },
    timeout=30,
)
data = res.json()
201 Created
{
  "upload_id": "6f1c2a9e-4b7d-4c3a-9e2f-0a1b2c3d4e5f",
  "upload": {
    "method": "PUT",
    "url": "https://data.b7r.app/storage/v1/object/upload/sign/custom-api-uploads/2f9a6e1c-0d4b-4e8a-9c7f-1b2a3c4d5e6f/6f1c2a9e-4b7d-4c3a-9e2f-0a1b2c3d4e5f?token=sample",
    "headers": {
      "content-type": "image/png"
    },
    "expires_at": "2026-12-01T08:01:00.000Z"
  },
  "expires_at": "2026-12-01T09:00:00.000Z"
}

Send the file

PUT the file to the address
import { readFile } from "node:fs/promises";

const file = await readFile("design.png");
const response = await fetch(upload.upload.url, {
  method: "PUT",
  headers: upload.upload.headers,
  body: file,
});
if (!response.ok) throw new Error(`upload failed: ${response.status}`);
curl -sS -X PUT "$UPLOAD_URL" \
  -H "content-type: image/png" \
  --data-binary @design.png

Purposes

PurposeArea it needsFile typesLargest file
designproducts:writeimage/png, image/jpeg, image/webp25 MB
design_originalproducts:writeapplication/pdf25 MB
my_store_imagemy_store:writeimage/png, image/jpeg, image/webp5 MB
ticket_imagetickets:writeimage/png, image/jpeg, image/webp5 MB
avatarsettings:writeimage/png, image/jpeg, image/webp2 MB
brand_logosettings:writeimage/png, image/jpeg, image/webp2 MB

Titles and headings of every page. llms-full.txt holds the full text.