Skip to content
Sign in

Transfers

Stream large files through the SDK, build an inventory, and download or export workplace Files.

Move large files without loading them into memory, list everything in a workplace, and copy current or retained work to local disk. Every transfer uses temporary grants issued by the API and verifies bytes before treating them as complete.

Stream bytes through the SDK

The streaming methods handle files up to decimal 2 GB (2,000,000,000 bytes). uploadFile and downloadFile are whole-buffer methods capped at 64 MiB; downloadFile rejects larger declared content before fetching any bytes.

Upload from a source

  1. Call prepareFileUploadFromSource on a seekable source. It computes the immutable request using bounded reads.
  2. Persist that request.
  3. Call uploadFileFromSource with the same bytes. Each reread part is checked before it's sent.

Reopening a source doesn't let you change the saved operation, content, or deadline. Your code closes the source on success, failure, or cancellation. CLI files put uses bounded reads too.

Before uploading parts, the SDK checks the operation and sends only parts that are missing, so a part accepted before a lost response isn't sent again. It still checks the whole local source against the frozen request, and the API verifies the completed object before publishing. If every byte is already uploaded and you no longer have the source, use files finalize UPLOAD_ID. Replaying admission keeps the original expiry and returns an expired result after the deadline.

Inspect uploaded parts

agent-workplace files parts UPLOAD_ID --json

The response has upload, the current operation status, and presentPartNumbers:

  • For an open upload, a complete list of present part positions (at most 239). [] means none.
  • null means inspection doesn't apply in the current state, such as during creation, completion, or after a final result. Check upload to decide whether to wait, finalize, or handle the outcome.

This is evidence of presence and size, not a checksum. The response never includes provider identifiers, ETags, or grants, and current authority is checked before and after storage is inspected. Incomplete, duplicate, malformed, or unavailable listings fail; never treat an error or null as an empty list and resend everything. Inspection doesn't lock against another process or an issued write grant, so serialize retries of one operation.

Download to a sink

downloadFileTo writes to an asynchronous sink with backpressure and returns file metadata only after full SHA-256 verification. It pins the revision and renews short-lived grants for bounded Range reads, rechecking access each time. It never switches to a newer revision if the pinned content expires or becomes unavailable.

To make a download resumable:

  1. Before starting, save the revision reference, byte length, and SHA-256.
  2. Pass them in resume with the durable offset, and give the sink a read(offset, length) function for the bytes it already has. The SDK rehashes that prefix; a saved digest or offset alone doesn't prove integrity.
  3. Make the sink's checkpoint(offset) flush bytes durably before saving the offset.

Keep partial output untrusted and unpublished until the download succeeds. The sink's owner closes resources and handles interrupted writes and local file ownership.

Build an inventory with the SDK

walkFilesTree lists the active current contents of a folder; omit parentId for the workplace root. File events include pinned revision metadata:

for await (const item of client.walkFilesTree(auth, {
  workplaceId,
  parentId,
})) {
  if (item.kind === "file") {
    // Choose a safe destination yourself; item.path contains untrusted names.
    console.log(item.path, item.file.revisionReference);
  }
}

walkRetainedFiles lists all retained work, including earlier revisions and trash. Entry events keep folder relationships, names, and trash metadata; revision events include expiry and restoration metadata:

for await (const item of client.walkRetainedFiles(auth, { workplaceId })) {
  if (item.kind === "revision") {
    console.log(item.file.revisionReference, item.file.isCurrent);
  }
}

Both stream metadata through ordinary authorized reads. They don't fetch bytes or reach expired or purged content; copy each pinned revision's bytes with downloadFileTo. Retention and permissions can still change before that read.

An inventory is not a snapshot

Event or fieldMeaning
startCarries a change checkpoint for the enumeration.
issueContent disappeared, or a tree entry was seen again during concurrent moves.
changedSinceListingThe file's version changed between listing and reading its metadata.
completeEnumeration ended. It doesn't mean files were downloaded; check its issue count.
workplaceChangesobserved, none_observed, or unknown (incomplete history coverage) for the interval.

Changes can involve other folders. Authorization and transport errors stop iteration and propagate. If you copy bytes afterward, check changes again from the start checkpoint to cover that time too.

Names and path segments are untrusted. A filesystem consumer must handle unsafe names, case collisions, symbolic links, and existing destinations without silently overwriting local work. These methods don't restore archives or extend retention.

The tree walker keeps one page per depth and an index of visited IDs, which grows with the number of entries. For large trees, pass { visits } as the third argument: a fresh FilesTreeVisitStore per traversal whose addIfNew(id) returns true exactly once per ID and propagates storage failures. The CLI uses a disk-backed index. The retained inventory uses ordered pages and needs no visited-ID index.

Download a folder or export retained work

Create a private directory for operation records first:

mkdir -p private-files
chmod 700 private-files
# Active current contents beneath a folder; use root for all current Files.
agent-workplace files get-folder root \
  --output ./current-files --operation private-files/current-export.json --json

Both need a new destination directory whose parent exists, and a private operation path outside it. Recovery requires a POSIX filesystem. Keep the operation file and the private .awp-export-* directory beside it until recovery is done; they hold the inventory and per-file receipts, grow with the exported metadata and attempts, and contain no API keys or grants.

OutputLayout
Folder downloadObserved names, including empty folders. The manifest lives in the private operation directory.
Retained exportBytes at files/FILE_UUID/REVISION_UUID; manifest.ndjson keeps names, parents, empty folders, trash, expiry, and restoration metadata.

The result reports both manifest and inventory paths. This exports Files only; for Mail, see Export retained Mail. It isn't an archive import or restore tool.

How export runs

The CLI finishes and saves its inventory before copying, then downloads pinned revisions with length and SHA-256 checks. It streams bytes and records rather than loading everything into memory. Unsafe names, local collisions, missing content, and authorization failures are reported instead of overwriting or skipping work. Export doesn't reserve content or extend its lifetime.

Repeat the exact command to resume. Completed files are verified again under current authorization. The frozen inventory isn't refreshed, so use a new operation and destination to pick up later changes or resolve omissions. After a crash, unknown files, replaced directories, and unrecorded paths are preserved, and the command refuses to overwrite them when safe recovery can't be established.

Read the result

With --json, stdout holds the result: plannedFiles, copied, failed, unattempted, stopped, and the manifest paths. failed counts every issue, including folder failures. A partial result also exits nonzero with a safe diagnostic on stderr. If authority is lost, the CLI stops downloading and reports what wasn't attempted.

The result is always non_snapshot. workplaceChanges covers both the inventory and copying and can include changes outside the selected folder; none_observed is not a snapshot guarantee, and an expired change window reports unknown with a partial result. Each manifest attempt records the inventory observed, successful downloads, failures, and a final result if it finished; a killed attempt may have none. Inspect the latest result and its manifest before treating an export as complete.

On this page