Uploads
Uploading images to Nooknear takes two steps: your server calls POST /v1/media/upload-request to get a signed URL, then the file is sent with PUT straight to object storage (Cloudflare R2). Because the file never passes through the API server, large files don’t put load on your backend or ours.
The upload request
curl -X POST https://api.nooknear.com/v1/media/upload-request \
-H "X-API-Key: $NOOKNEAR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: menu-17-adana-1" \
-d '{
"resourceType": "menu-item",
"resourceId": "17",
"filename": "adana.png",
"mimeType": "image/png",
"sizeBytes": 1048576,
"outputFormats": ["webp", "jpeg"],
"tags": ["mains", "dish:adana-kebap"],
"metadata": { "dish": "adana-kebap", "source": "menu-editor" }
}'
Response, 201 Created:
{
"uploadUrl": "https://...r2.cloudflarestorage.com/...",
"assetId": "b2a1c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d",
"expiresAt": "2026-12-06T12:15:00.000Z"
}
Fields and limits
| Field | Required | Rule |
|---|---|---|
resourceType |
Yes | ^[a-zA-Z0-9-]{1,50}$. The kind of record the image belongs to, such as product, event or menu-item. |
resourceId |
Yes | ^[a-zA-Z0-9_-]{1,128}$. The record’s ID in your system. |
filename |
Yes | 1–255 characters. The original file name, kept for reference. |
mimeType |
Yes | image/jpeg, image/png, image/webp, image/gif or image/avif. |
sizeBytes |
Yes | Positive integer, at most 10 MB (10,485,760 bytes). |
outputFormats |
No | ["webp"], ["jpeg"] or ["webp", "jpeg"]. |
tags |
No | Up to 20 tags, each matching ^[a-zA-Z0-9:_.-]{1,64}$. |
metadata |
No | A JSON object, at most 4 KB when serialized. |
A field that breaks these rules returns 400. See Errors and limits.
resourceType and resourceId become part of the CDN URL, so use opaque IDs rather than personal data such as emails or phone numbers.
Quota check
At upload-request time, the declared sizeBytes is checked against your plan’s per-file limit and total storage quota. If either is exceeded, the request is rejected with 429 QUOTA_EXCEEDED and no upload URL is issued. Check your current usage with GET /v1/tenants/:tenantId/usage.
outputFormats and JPEG output
WebP variants (thumb, small, medium, large) are always produced, whether you omit outputFormats or send only ["jpeg"].
Add "jpeg" and you also get one full-size JPEG variant, returned under variants.jpeg:
- Longest side capped at 2048 px; smaller images are never enlarged.
- EXIF orientation is applied, then all metadata (EXIF, location and so on) is stripped.
- Transparency is flattened onto white.
- sRGB color space, quality 90.
This variant exists for places that don’t accept WebP. The Instagram Graph API, for example, doesn’t accept WebP in image_url; you can pass the JPEG variant URL directly. Any other value (such as "png") returns 400. AVIF output and on-the-fly format selection from the URL are coming soon.
Tags and metadata
Tags and metadata help you find and group images later.
tags: short flat labels such aspoolorcover. Akey:valuestyle likedish:adana-kebapworks too. When listing,tags=a,breturns only images carrying all of the tags.metadata: a small free-form JSON object. When listing, you pass a JSON fragment and get images whose metadata contains it.
Both are returned by GET /v1/media/:assetId and GET /v1/media, and can be changed later with PATCH /v1/media/:assetId. Details in Listing and filtering.
The PUT step
Send the raw file bytes to uploadUrl with PUT:
curl -X PUT "$UPLOAD_URL" \
-H "Content-Type: image/png" \
--data-binary @adana.png
await fetch(uploadUrl, {
method: 'PUT',
headers: { 'Content-Type': 'image/png' },
body: fileBuffer // a Buffer in Node.js, a File or Blob in the browser
});
Rules:
- The
Content-Typeheader must exactly match themimeTypeyou declared. It’s part of the signature; if it differs, storage returns403. - The URL is valid for 15 minutes (
expiresAt). If it expires, make a new upload request. - Send the body as raw bytes, not
multipart/form-data(use--data-binaryin curl, not-F). - Don’t add
X-API-Keyto thePUT; authorization lives in the signed URL. - The real file type is checked again on the server. A file named
.pngthat contains something else won’t be processed.
Status lifecycle
Every asset has a status:
| Status | Meaning |
|---|---|
pending |
The asset exists; waiting for the file or for a worker. |
processing |
The image is being processed and variants generated. |
ready |
Variants are ready; variants is populated. |
failed |
Processing failed even after retries. |
deleted |
Deleted. The API returns 404 for this asset. |
The processing job is queued together with the upload request. If the file hasn’t arrived yet or a transient error occurs, the job is retried with increasing delays and the asset goes back to pending in between. Once all attempts are used up, the status becomes failed. So do the PUT right after the upload request.
For a failed asset, create a new upload request and send the file again; you can clean up the old asset with DELETE.
Today you learn the status by polling GET /v1/media/:assetId. Webhook events such as asset.ready and asset.failed are coming soon.