@gj-kit/expo-media recipes
Each code block reuses a public-contract example already type-checked in the package README.
1. Create a media kit with explicit upload limits
Section titled “1. Create a media kit with explicit upload limits”Wire only the application upload API and a declared size policy before adding platform adapters.
Outcome: An Expo-backed media kit while your application keeps upload authorization.
Application-owned boundary:
Implement uploadApi in your app for upload intent and completion, then declare explicit file limits.
import { createMediaKit, type MediaUploadApi } from '@gj-kit/expo-media';
type Asset = { readonly id: string };declare const uploadApi: MediaUploadApi<Asset>; // Your app owns auth and upload URLs.
export const media = createMediaKit({ api: uploadApi, limits: { image: { maxBytes: 15 * 1024 * 1024 } },});2. Classify and recover an interrupted upload
Section titled “2. Classify and recover an interrupted upload”Narrow unknown errors into safe recovery metadata before the application reconciles storage.
When an upload dies mid-flight the error narrows into URL-free recovery metadata — a stage plus frozen object records — never the presigned URL and never the native error text.
import { createMediaKit, mediaUploadFailureInfo } from '@gj-kit/expo-media';import type { MediaUploadApi, MediaUploadFailureInfo } from '@gj-kit/expo-media';
declare const uploadApi: MediaUploadApi<{ readonly id: string }>; // App owns auth + upload URLs.declare function reconcile(failure: MediaUploadFailureInfo): Promise<void>; // App owns cleanup.
// `limits` is required, and there is no numeric escape hatch:// createMediaKit({ api: uploadApi });// -> error TS2345: Argument of type '{ api: MediaUploadApi<...>; }' is not// assignable to parameter of type 'MediaKitConfig<...>'.export const media = createMediaKit({ api: uploadApi, limits: 'server-enforced' });
export async function recover(error: unknown): Promise<void> { const failure = mediaUploadFailureInfo(error); if (!failure) throw error; // Not an upload failure — never swallow it. // failure.stage : 'intent' | 'put' | 'complete' // failure.orphanedObjects : readonly { objectName; contentType; sizeBytes; // storageState: 'uploaded' | 'possibly-uploaded' }[] // No presigned URL and no native error text ever reach this value. await reconcile(failure); throw error;}Use the complete API reference for every export and import path.