⭐️ Reading attachments with JavaScript

For non-tabular files (JSON, text, images, PDFs, etc.), you can read attachment bytes directly from a JavaScript code cell using fetch() against the document's attachment URL.

Prefer CSV or SQLite when you can. If your data is tabular, store it as a .csv or .sqlite attachment and query it through a request page instead. You get caching, deduplication, and SQL for free — see ⭐️ Querying tabular data files. Reach for fetch() only when the file genuinely isn't tabular.

Reading an attachment with fetch()

Every file in .moment/attachments/ is served back to the document at a stable URL. From a code cell, just fetch() it and parse the response however you like.

Text files use .text(), binary files use .arrayBuffer() or .blob().

Tips & gotchas

Parse on the consumer side when possible. Returning raw text or an ArrayBuffer keeps the cached value small and lets downstream cells decide how to interpret it.

Large files cost memory. Code cell results are held in memory for the life of the document session. For multi-MB JSON or binary blobs, slice or stream rather than returning the whole payload.

Sensitive data is committed. Attachments live in git, so treat anything you read this way as public to anyone with repo access.