14. Files
GetFileAsync(fileRef)
async· returns{ bytes, mime, filename, size } | null
Reads a stored file's contents.
Prop
Type
const file = await context.functions.GetFileAsync(context.record.AttachmentId);
if (!file) throw new Error("Attachment is missing or was deleted");
log(file.filename + " · " + file.mime + " · " + file.size + " bytes");Returned value
Prop
Type
Resolves to null — rather than throwing — when the id is unknown, the file was deleted, or the record has no stored content. Always check before using the result.
Legacy code received the Uint8Array directly from this call. It now returns a wrapper object, so GetFileAsync(...) is not itself an array — read file.bytes.
This is the only file function
Processes can read files but cannot write them. There is no upload, no download-from-URL, and no folder creation, listing, or traversal. uploadFileFromUrl, CreateFolderAsync, and CreateMultipleFoldersAsync were part of the previous backend and no longer exist — calling them throws.
Files reach the platform through the UI or the API. A process reacts to them after the fact, typically from an afterCreate on the entity holding the file reference.
Working with the contents
Pair GetFileAsync with XLSX to parse uploaded spreadsheets:
/** @event afterCreate @entity imports */
const file = await context.functions.GetFileAsync(context.record.FileId);
if (!file) throw new Error("Uploaded file could not be read");
if (!file.mime.includes("sheet") && !file.filename.endsWith(".xlsx")) {
throw new Error("Please upload an .xlsx file — got " + file.mime);
}
const workbook = XLSX.read(file.bytes, { type: "array" });
const rows = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]]);
await context.functions.createBulk("customers", rows);Or forward a file to an external service. bytes is a Uint8Array, so encode it before putting it in a JSON body:
const file = await context.functions.GetFileAsync(context.record.DocumentId);
if (!file) return;
let binary = "";
for (const b of file.bytes) binary += String.fromCharCode(b);
const base64 = btoa(binary);
await context.functions.http({
method: "POST",
url: context.env.OCR_ENDPOINT,
headers: { "Authorization": "Bearer " + context.env.OCR_TOKEN },
body: { filename: file.filename, mime: file.mime, content: base64 }
});The whole file is loaded into the process. Check file.size before parsing something that may be very large, and remember the default process timeout is 30 seconds — raise it with @timeout for heavy files.
const MAX = 10 * 1024 * 1024;
if (file.size > MAX) throw new Error("File is too large to process (" + file.size + " bytes)");