Files & share
Getting files in and out of the app: openFilePicker opens the host's native picker and resolves
to File handle(s); share hands a media file to the OS share sheet.
At a glance
const file = await openFilePicker({ accept: 'image/*' })
if (file) {
const form = new FormData()
form.append('photo', file)
await fetch('https://api.example.com/upload', { method: 'POST', body: form })
}openFilePicker
openFilePicker(options?: { accept?: string, multiple?: false }): Promise<File | null>
openFilePicker(options: { accept?: string, multiple: true }): Promise<File[]>Single-pick by default: resolves to one File, or null if the user cancels. With
multiple: true it resolves to a File[] — empty on cancel, never null. accept filters what
can be picked, same idea as an HTML <input accept> ('image/*', '.pdf').
const many = await openFilePicker({ accept: 'image/*', multiple: true })
console.log(`picked ${many.length}`)The returned handles carry id / name / size only — there is no path and no direct byte
access from JS; the bytes stay host-side. Use a File where the SDK accepts one: FormData
uploads, image sources (UIImage(file), Texture2D.load(file)), and share().
share
share(media: File | FetchResponse, text?: string): voidShare a media file (image/video) via the OS share sheet. media is a picker/camera File or a
fetched FetchResponse; text is an optional caption/message. Fire-and-forget — no result comes
back.
Per-platform behavior:
- iOS — opens the share sheet; it also lets the user save to Files/Photos.
- web — saves (downloads) the file.
const photo = await CameraViewer.takePhoto()
share(photo, 'Look at this')See also
- Networking — the
Fileclass,FormData,FetchResponse - CameraViewer — the other source of
Filehandles