Skip to content
scroll to zoom · drag to pan

Mobile — React Native and Expo

The mobile path is not “the web path in a WebView”. Two subpaths exist because a phone has constraints a browser does not: the OS suspends and kills apps, the signal comes and goes, and a binary is not a secret.

Section titled “Uploads through your backend (recommended)”

The phone talks to your backend with its own session. Your backend holds the amk_rt_* runtime key, pins the tenant, and forwards only the routes an upload needs. The bytes never pass through it — they go from the phone straight to object storage on presigned URLs.

import { UploadTask, resumePending } from "@nitida/sdk/expo"; // re-exports @nitida/asset-uploader-expo
const task = new UploadTask({
endpoint: "https://api.your-app.com/nitida", // your proxy
tenantCode: "your-tenant", // the proxy overrides it
apiHeaders: { Authorization: `Bearer ${sessionToken}` },
file: { uri: durableFileUri, mime: "video/mp4", name: "lote-12.mp4" },
visibility: "private",
});
task.on("state", ({ phase }) => setStatus(phase)); // "waiting-retry" = no signal
task.on("progress", ({ ratio }) => setProgress(ratio));
const { sha256, assetId } = await task.start();

The routes the proxy forwards — and nothing else:

method path
POST /assets/upload-url, /assets/process
POST /assets/multipart/initiate, /refresh-urls, /complete, /abort
GET /assets/multipart/status/:uploadId, /assets/by-hash/:sha

For each request it checks your session, sets tenantCode (and, if you want, visibility: "private") in the body, adds Authorization: Bearer amk_rt_… and X-Tenant-Code, and passes the JSON answer back. A tested reference implementation ships in the package: @nitida/asset-uploader-expo/examples/upload-proxy.ts (createNitidaUploadProxy({ upstream, runtimeKey, tenantCode, forceVisibility, authenticate })), exercised end to end — upload, refusal without a session, refusal of other routes, resume after kill — in the package’s tests.

Bad signal: retries, resume, and what the app should do

Section titled “Bad signal: retries, resume, and what the app should do”
  • Every transfer and API call is retried on a network error, 5xx, 408 or 429 with exponential backoff and jitter. Other 4xx fail at once.
  • If the app is killed or the phone reboots, call resumePending() after sign-in with the same endpoint/apiHeaders. It uploads only the parts the server does not have and completes; a server session older than 24 h restarts cleanly, and the sha dedupe guarantees one asset.
  • Give the task a durable file:// URI: copy the picked or recorded file into the app’s document directory first. Resume needs it to still be there.

Details and defaults: Uploads that survive a reload.

visibility: "private" is stored before the first byte lands. On a tenant whose default visibility is private, every public URL of the asset — image variants, raw original, poster, HLS master and segments — answers 404 from that first byte; your backend serves it with a signed URL. See Access and privacy.

createExpoUploader — a key on the device

Section titled “createExpoUploader — a key on the device”
import { NitidaClient } from "@nitida/sdk/server";
import { createExpoUploader } from "@nitida/sdk/expo";
const task = createExpoUploader(client, {
file: { uri, mime: "image/jpeg", name: "photo.jpg" },
visibility: "private",
});

The transfer runs in a native background session — URLSession on iOS, WorkManager on Android — so it survives backgrounding, screen lock and JS suspension. A JS-driven upload survives none of those.

import { compressImage } from "@nitida/sdk/native";

A thin pass-through to the native compressor, with the same JS API as the web one, so call sites are identical across web and React Native.

The concurrency default is 1, and leave it there

Section titled “The concurrency default is 1, and leave it there”

Mobile batches sequentially, and resumePending resumes one file at a time. A phone running four pipelines at once does not finish sooner — low-end Android runs out of memory and the OS kills the process. Multipart parts default to 2 in flight for the same reason.

iPhones produce HEIC by default. It decodes natively in ~136 ms where the engine supports it, falling back to a 341 kB WASM decoder only where it does not — so most users never fetch the decoder.

Worth confirming on a real device rather than a simulator: the simulator’s engine is not the phone’s.