---
title: "Recipe: transfers the system finishes"
description: "@exact/background-transfer hands an upload or download to the system, which finishes it after the app is suspended or terminated."
modificationDate: "2026-11-20"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: transfers the system finishes

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/background-transfers: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

On iOS, macOS and Android, data code can start a transfer that survives suspension. On the web,
`backgroundFetchStatus().available` is false. Grant `net.fetch` for the
URL, `fs.read` for each upload file and `fs.write` for `saveTo`.

```prompt Add a transfer the system finishes
Make the Exact app in this folder hand an upload or a download to the system, which finishes it after the app is suspended or terminated. Use https://github.com/expo/exact/blob/main/docs/recipes/background-transfers.md as the source for each step. The Exact checkout has the same page at docs/recipes/background-transfers.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me. Find the Exact checkout (the folder with scripts/exact.mjs); if you cannot find it, ask me where it is.
2. If I did not say which transfer to hand over, propose it and ask me. Background transfers run on iOS, macOS and Android; on the web `available` is false and the app uses `fetch`. If the app runs on none of those native targets, tell me and stop.
3. Install the package: `bun <exact2>/scripts/exact.mjs add background-transfer .`.
4. In app.ts, start the transfer with `backgroundFetch` from data code only, and grant each `url`, `bodyFrom` and `saveTo` (`net.fetch`, `fs.read`, `fs.write`). Put no credential in app.contract. On Android, a start within five seconds of a person's press, key or notification tap while the app is visible uses a user-initiated job on Android 14 and later, foreground work on Android 12 and 13. Neither requires notification permission or an import of `@exact/notifications`. On Android 13 and later, with permission denied, the app appears in Task Manager, outside the notification drawer. Other starts use ordinary WorkManager work.
5. On the root, handle `backgroundfetchsuccess`, `backgroundfetchfail` and `backgroundfetchabort`. Keep what the transfer carried, then call `retireBackgroundFetch`; until then the event comes again at later launches.
6. Add tests in app.test.contract for a transfer that succeeds and one that fails, and on the web for the `fetch` path. `packages/background-transfer/test` in the Exact checkout is a whole example.
7. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 8) and report it; do not keep trying.
8. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
9. Tell me which transfer the system now finishes, the grants you added, and what the tests and verify reported.
```

```ts
import { backgroundFetch } from '@exact/background-transfer';
await backgroundFetch({ id: `photo:${key}`, requests: [{ url, form: [
  { name: 'album', value: album }, { name: 'photo', from: 'app:/data/out/photo.jpg', contentType: 'image/jpeg' }
] }] });
```

Use `bodyFrom` for a raw file or `form` for up to 256 ordered parts. Both
default to POST. The host streams files into a private snapshot before
answering. For a form it sets Content-Type and the boundary. A file part
defaults to the source filename and `application/octet-stream`. Form
metadata is limited to 64 KiB. On Android this includes the URL and headers.

The root hears `backgroundfetchsuccess`, `backgroundfetchfail` or
`backgroundfetchabort` in a wake. Read each response at `records[index].path`.
With `saveTo` it belongs to the app. Otherwise the host keeps it at
`app:/data/transfers/<id>/<index>` (grant `fs.read app:/data`). The id is
percent-encoded except for ASCII letters, digits, `-` and `_`.
`retireBackgroundFetch` removes the kept files and frees the id. If Android
rejects retirement with `UnknownError` (for example, a locked secret store),
retry.

On Android, WorkManager waits for a network. Three system stops or five consecutive
network failures without a kept response end in `fetch-error`. A drive owns its transfers
even with `--bind background-transfer`. `--reset-storage` cancels its jobs and frees its ids.

A transfer started within five seconds of a press, key or notification tap while the
app shows is person-initiated, including one started by a timer. Android 14 and later run it as a
user-initiated job with a notification (a tap raises
`backgroundfetchclick`) and no time limit, Android 12 and 13 as foreground
work started while the app shows. The system's stops never fail it: after three it
waits for the app to be opened. Every other start is a program's.

Neither requires `POST_NOTIFICATIONS` or `@exact/notifications`. When
permission is denied, Android 13 and later list the app in Task Manager,
outside the notification drawer
([UIDT](https://developer.android.com/develop/background-work/background-tasks/uidt),
[foreground work](https://developer.android.com/develop/ui/views/notifications/notification-permission)).

The event reaches the running app, or Android boots it with no window and
its data module loaded. The job lasts until the handler ends and its writes
are on disk. A link or share then opens at its launch location. An unretired
ending gets up to three background wakes, then each visible launch. A
force-stop aborts unfinished transfers; the next launch hears the abort.
Transfers recover after a reboot or update without opening the app.
`packages/background-transfer/test/checklist.md` lists the platform drives.
