---
title: "Recipe: things dragged into the app"
description: "A node with drop takes files, text and links from other apps; a dropped file is lent, so the app copies attachments it keeps."
modificationDate: "2026-11-28"
---

> ## 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: things dragged into the app

<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/drag-in: <what was wrong or missing>"`

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

</AgentInstructions>

A `drop` node's `DragEvent` has `files` (`doc:` handles), `text` and
`url`; check `url` before following it. `dragover` says where a drag is,
to draw where it lands ([grammar](https://exact.expo.dev/reference/contract-grammar/events.md#pointer)).

**A dropped file is lent, not given.** Its handle reads the source's file,
which may change or go (Mac, Windows, Linux, a browser's file handles),
or a copy (iOS, Android, a Mac promise, other browsers), and ends with the
session. Keep it one of two ways:

```prompt Use this recipe in my app
Make the Exact app in this folder do what this recipe describes. Use https://github.com/expo/exact/blob/main/docs/recipes/drag-in.md as the source for each step. The Exact checkout has the same page at docs/recipes/drag-in.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. Read the recipe. If it leaves a choice that I did not make (which screen, which data, which platforms), propose one and ask me before you write code.
3. Do what the recipe says, in its order, with its tags, properties, functions and grants. Its component, state and URL names are examples. Change nothing else in the app.
4. Add a test in app.test.contract for each thing a person does that you changed. Copy the recipe's `contract-test` block where it has one. A drive operation the recipe shows (`call`, a ticket answer such as `tap @N accepted`) is not a test step: run it with `bun exact.mjs agent`.
5. 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 6) and report it; do not keep trying.
6. 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.
7. Tell me what you changed, what the tests and checks reported, and what I must still do by hand.
```

- **As the app's own**: copy it into `app:/data` in a mutation the drop
  sends, as below.
- **As the person's document**, in place: declare its type
  (`file_handlers`) and grant `doc.keep` and `fs.write doc:/`;
  [the reference](https://exact.expo.dev/reference/developer/generate-typescript-data-source-types.md#documents-the-person-chose-doc) says which
  drops reopen.

```contract
shape Kept
  id: string
  name: string
  size: number

shape Reply
  ok: bool

component Attachments
  resource kept = loadKept() as shape Kept[] else empty()
  mutation copied as shape Reply queue refreshes kept
  action took(e: DragEvent)
    send copied = keepDropped(e.files)
  view
    column testId="zone" drop=took flex=1
      text "Drop files here"
      for a in kept key=a.id
        text `${a.name} (${a.size} B)` testId=`file-${a.id}`
```

In `app.ts` (import `Storage` too):

```ts
const DIR = 'app:/data/attachments';
const LIST = `${DIR}/list.json`;
export const grants = `fs.read doc:/\nfs.read ${DIR}\nfs.write ${DIR}`;

const listed = (storage: Storage) =>
  storage.fs.readFile(LIST).then((b) => JSON.parse(new TextDecoder().decode(b)),
    (e) => (e.code === 'ENOENT' ? [] : Promise.reject(e)));

const sources: Sources = {
  loadKept: async (_args, _store, storage) => {
    const out = [];
    for (const a of await listed(storage)) out.push({ ...a, size: (await storage.fs.stat(`${DIR}/${a.id}/${a.name}`)).size });
    return out;
  },
  keepDropped: async ([files], _store, storage) => {
    const list = await listed(storage);
    for (const file of files) {
      if ((await storage.fs.stat(file)).isDirectory) continue;
      const name = file.split('/').pop()!;
      const id = String(+(list.at(-1)?.id ?? -1) + 1);
      await storage.fs.mkdir(`${DIR}/${id}`);
      const path = `${DIR}/${id}/${name}`;
      list.push({ id, name });
      await storage.fs.copyFile(file, path)
        .then(() => storage.fs.atomicWriteFile(LIST, new TextEncoder().encode(JSON.stringify(list))))
        .catch((e) => storage.fs.rm(path).finally(() => { throw e; }));
    }
    return { ok: true };
  },
};
```

A copy not listed is removed if it can, and throws ([after a
write](https://exact.expo.dev/recipes/after-a-write.md)); `copyFile` passes `readFile`'s 16 MiB limit; one
writer is assumed.

## Testing it

`fixtures/a/notes.txt` has 19 bytes, `fixtures/b/notes.txt` 5:

```contract-test
test "two files of one name are kept"
  tap "zone" drop file "fixtures/a/notes.txt"
  tap "zone" drop file "fixtures/b/notes.txt"
  clock settle
  reload
  clock settle
  expect text "file-0" == "notes.txt (19 B)"
  expect text "file-1" == "notes.txt (5 B)"
```
