Read file content: read-document for any file (as stored, PDF or
HTML conversion, or text), byte-exact downloads, Range and chunked
downloads past the response cap, format conversion, and thumbnails.
Results are ::microsoft::onedrive/FileContent: bytes is always the
raw body (a JSON file stays bytes), and text is filled in when the
file is textual by MIME type or extension.
How downloads work. GET {item}/content answers 302 Found with
a short-lived pre-authenticated URL, which Hot follows (without the
Authorization header). Range requests go straight to the item's
@microsoft.graph.downloadUrl (valid about an hour, no token), as
Graph requires.
Limits. Every single response is capped by the runtime's
http.max-response-bytes (16 MiB by default): download switches to
Range-chunked downloads when a file is larger. Format conversion
(?format=pdf / html) only accepts source files up to 2 MB.
Permissions. Files.Read / Files.Read.All (delegated),
Files.Read.All or Sites.Read.All (app-only; conversion is
documented as needing Files.ReadWrite.All app-only), or
Sites.Selected / Files.SelectedOperations.Selected with a grant.
Values
CONVERT_MIME
CONVERT_MIME: Map {
pdf: "application/pdf",
html: "text/html",
jpg: "image/jpeg",
glb: "model/gltf-binary"
}
DEFAULT_DOWNLOAD_CHUNK
DEFAULT_DOWNLOAD_CHUNK: Int 8388608
DOWNLOAD_URL_KEY
DOWNLOAD_URL_KEY: Str "@microsoft.graph.downloadUrl"
FORMATS
FORMATS: Vec [
"auto",
"original",
"pdf",
"html",
"text"
]
Functions
convert
fn (item: Any, format: Str): ::microsoft::onedrive/FileContent
fn (item: Any, format: Str, opts: Map): ::microsoft::onedrive/FileContent
GET {item}/content?format={format} - download a file converted by
Graph: "pdf" (Word, Excel, PowerPoint, RTF, ODF, HTML, Markdown,
EML/MSG, TIFF, Loop, ...), "html" (Loop, Fluid, Whiteboard) or
"jpg" (with opts.width and opts.height). The source must be at
most 2 MB. Returns a FileContent with source: "convert".
pdf ::microsoft::onedrive::content/convert("/Specs/Design.docx", "pdf")
convert-params
fn (format: Str, opts: Map): Map
The query parameters for a conversion (pure): format, plus width /
height (required by Graph for jpg).
Example
::microsoft::onedrive::content/convert-params("PDF", {}) // {format: "pdf"}
::microsoft::onedrive::content/convert-params("jpg", {width: 800, height: 600}) // {format: "jpg", width: 800, height: 600}
download
fn (item: Any): ::microsoft::onedrive/FileContent
fn (item: Any, opts: Map): ::microsoft::onedrive/FileContent
GET {item}/content - download a file's exact bytes as a FileContent
(Hot follows Graph's 302 to the pre-authenticated URL). When the file
is larger than http.max-response-bytes, it is fetched again in Range
chunks (download-chunked). Shared items (remoteItem) are read from
the owner's drive. opts.range: {start, end} downloads a slice.
pdf ::microsoft::onedrive::content/download("/Contracts/MSA.pdf")
pdf.mime-type // "application/pdf"
pdf.bytes
download-chunked
fn (item: Any): ::microsoft::onedrive/FileContent
fn (item: Any, opts: Map): ::microsoft::onedrive/FileContent
Download a file in Range requests of opts.chunk-size bytes (default
8 MiB; keep it under http.max-response-bytes) from its download URL
and join them, so files larger than one response can be read. The
whole file is still held in memory.
Example
big ::microsoft::onedrive::content/download-chunked("/Video/launch.mp4", {chunk-size: 4194304})
big.size
download-range
fn (item: Any, start: Int, end: Int?): ::microsoft::onedrive/FileContent
fn (item: Any, start: Int, end: Int?, opts: Map): ::microsoft::onedrive/FileContent
Download bytes start..end (inclusive) of a file with a Range
request on its pre-authenticated download URL (Graph ignores Range on
/content). Returns a FileContent with source: "range".
Example
// The first KiB
head ::microsoft::onedrive::content/download-range("/Reports/Q3.pdf", 0, 1023)
head.bytes
// From byte 1024 to the end of a file in another drive
tail ::microsoft::onedrive::content/download-range("01ABC", 1024, null, {drive: "b!xyz"})
tail.size
download-ranges
fn (size: Int, chunk-size: Int): Vec
Split size bytes into inclusive [start, end] ranges of at most
chunk-size bytes (pure): download-ranges(10, 4) is [[0, 3], [4, 7], [8, 9]].
Example
::microsoft::onedrive::content/download-ranges(10, 4) // [[0, 3], [4, 7], [8, 9]]
download-text
fn (item: Any): Str
fn (item: Any, opts: Map): Str
Download a file and decode it as UTF-8 text.
Example
notes ::microsoft::onedrive::content/download-text("/Notes/todo.md")
split(notes, "\n")
is-size-limit-error
fn (result: Result): Bool
True when a request failed because the response exceeded
http.max-response-bytes.
Example
::microsoft::onedrive::content/is-size-limit-error(err("response exceeds http.max-response-bytes")) // true
::microsoft::onedrive::content/is-size-limit-error("fine") // false
item-and-url
fn (item: Any, opts: Map): Map
Fetch an item (following remoteItem) and its pre-authenticated
@microsoft.graph.downloadUrl. Returns {item, url}; an Err for
folders.
Example
found ::microsoft::onedrive::content/item-and-url("/Reports/Q3.pdf", {})
found.url
found.item.size
list-thumbnails
fn (item: Any): Vec
fn (item: Any, opts: Map): Vec
GET {item}/thumbnails - thumbnail sets (id, small, medium,
large, each {url, width, height}; the URLs are short-lived and
pre-authenticated).
Example
sets ::microsoft::onedrive::content/list-thumbnails("/Photos/team.jpg")
first(sets).medium.url
range-header
fn (start: Int, end: Int?): Str
An HTTP Range value for bytes start..end inclusive (end null for
"to the end"): range-header(0, 1023) is "bytes=0-1023" (pure).
Example
::microsoft::onedrive::content/range-header(0, 1023) // "bytes=0-1023"
::microsoft::onedrive::content/range-header(1024, null) // "bytes=1024-"
read-document
fn (item: Any): ::microsoft::onedrive/FileContent
fn (item: Any, format: Str?): ::microsoft::onedrive/FileContent
fn (item: Any, format: Str?, opts: Map): ::microsoft::onedrive/FileContent
Read any file as a FileContent with its DocFile attached, for RAG
ingestion and file-triggered workflows. Shared items are followed to
the owner's drive; folders return an Err. See read-plan for the
formats:
"auto"(default) /"original"- the stored bytes: Office files as-is for a text extractor (hot.dev/libreoffice,pandoc, ...),textset for.txt/.md/.csv/.jsonand other text"pdf"- a PDF: converted by Graph when the file is convertible and at most 2 MB, otherwise (or when conversion fails) the original"html"- Loop / Whiteboard as HTML, otherwise the original"text"- text files only; an Err for binaries
format on the result says what you got (original, pdf, html
or text); check mime-type too.
doc ::microsoft::onedrive::content/read-document("/Specs/Design.docx", "pdf")
doc.format // "pdf" (or "original" when the docx was over 2 MB)
doc.file.version // eTag, for incremental re-indexing
read-document-text
fn (item: Any): Str
fn (item: Any, opts: Map): Str
read-document returning just the text; an Err when the result is not
textual (Office files, PDFs, images: extract text elsewhere).
Example
text ::microsoft::onedrive::content/read-document-text("/Notes/todo.md")
// From another drive
::microsoft::onedrive::content/read-document-text("01ABC", {drive: "b!xyz"})
read-plan
fn (item: Map, format: Str?): Map
Decide how read-document reads a file (pure): {action: "download" | "convert" | "error", format, reason?}. format is
auto/null (as stored), original, pdf, html or text.
pdf: a.pdfdownloads; a convertible file (Office, ODF, RTF, HTML, Markdown, EML/MSG, TIFF, Loop, ...) up to 2 MB converts; anything else, or larger, downloads as stored (format: "original")html: Loop / Fluid / Whiteboard up to 2 MB convert; others as storedtext: textual files (.txt,.md,.csv,.json,text/*, ...) download; others are an error (extract text elsewhere)
Example
::microsoft::onedrive::content/read-plan({name: "Design.docx", size: 1024}, "pdf") // {action: "convert", format: "pdf"}
::microsoft::onedrive::content/read-plan({name: "Big.docx", size: 5000000}, "pdf") // {action: "download", format: "original"}
thumbnail
fn (item: Any): ::microsoft::onedrive/FileContent
fn (item: Any, size: Str): ::microsoft::onedrive/FileContent
fn (item: Any, size: Str, opts: Map): ::microsoft::onedrive/FileContent
Download one thumbnail image: size is "small", "medium" (default)
or "large", from set opts.set (default "0"). Returns a
FileContent with source: "thumbnail".
Example
thumb ::microsoft::onedrive::content/thumbnail("/Photos/team.jpg", "large")
thumb.mime-type
thumb.bytes