Skip to main content
Read a file through the File point returned by ctx.store or held in a t.file field.
  • ctx.get(file) answers the metadata, { id, sha256, size, contentType }, or null once the file is retired.
  • ctx.get(file.bytes) answers the bytes, { contentType, size, bytes(), text() }, or null once the file is retired. It refuses Erased when the file’s unit was erased.
Both need a frame that clears the file’s label, and both work in queries and mutations.
Return only what the caller’s entry and audience permit: the query decides who sees the receipt, and the label decides who may run it at all. The customer file storage example shows the whole flow: labels, roles, the upload route and the reads.

Serve a public file at a URL

ctx.get(file.url) answers the URL the installation’s file route serves the file at, <origin>/api/storage/<file>, as a string. It answers null when no such file is stored, or once it is retired. Since a browser fetches the file at that URL outside any frame, only a public file kept in the clear has one. That is a file stored at label.public with no expiry. Any other file refuses Invalid (reason FileNotServed): a labelled file, or one sealed for an expiry. Read those files’ bytes with ctx.get(file.bytes) inside a function whose label clears them.
Like the other reads, it works in queries and mutations. In the test kernel the origin is https://installation.test unless kernel(app, { origin }) names another one.