api.files

get()

api.files.get(sourceId) → Promise<IaGenifyFile>

Reads a file back with its content. Text comes back as a string, anything else as bytes — and the object is ready to update.

GET /api/files/:idfreecontent included
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

Parameters

sourceIdstringrequired

From save() or list(). Missing → the SDK throws.

Returns

const file = await api.files.get(sourceId);

file.name;       // "report.md"
file.mimeType;   // "text/markdown"
file.content;    // a string, here — a Buffer for binary
file.sourceId;   // set, so update() works straight away
file.location;   // the kind of storage it is in
file.metadata;   // { size, mimeType, originalName }
file = api.files.get(source_id)

file.name        # "report.md"
file.mime_type   # "text/markdown"
file.content     # a str, here — bytes for binary
file.source_id   # set, so update() works straight away
file.location    # the kind of storage it is in
file.metadata    # {"size", "mimeType", "originalName"}

String or bytes, decided by the type

A file whose type is text-ish comes back as a string; everything else as a Buffer.

mimeTypecontent
text/* · json · xml · yaml · csv · markdown · plaina string
image/* · audio/* · video/* · pdf · anything elsea Buffer
const file = await api.files.get(sourceId);

if (typeof file.content === "string") {
  console.log(file.content.slice(0, 200));
} else {
  await fs.writeFile(`./${file.name}`, file.content);
}
from pathlib import Path

file = api.files.get(source_id)

if isinstance(file.content, str):
    print(file.content[:200])
else:
    Path(file.name).write_bytes(file.content)
The decision is the type, not the bytes

A text file saved without a mimeType comes back as a Buffer. Set the type at create() and this never comes up.

It reads the whole file

There is no range and no streaming: the content arrives in one response, as text or as base64 that the SDK decodes for you. For something large, that is memory on both sides — size it before you fetch.

const files = await api.files.list();
const target = files.find((f) => f.id === sourceId);

if (target.size > 20 * 1024 * 1024) {
  throw new Error(`${target.name} is ${Math.round(target.size / 1e6)} MB — too big to read in one go`);
}

const file = await api.files.get(sourceId);
files = api.files.list()
target = next(f for f in files if f["id"] == source_id)

if target["size"] > 20 * 1024 * 1024:
    raise ValueError(f"{target['name']} is {round(target['size'] / 1e6)} MB — too big to read in one go")

file = api.files.get(source_id)

Errors

CodeStatusWhen
— (thrown locally)—No sourceId passed.
file_not_found404No file of this account with that id.
file_missing_on_disk404The record exists and its bytes do not.
file_missing_on_disk is worth noticing, not retrying

The record and the bytes have come apart. Retrying answers the same thing; what helps is deleting the record and saving the file again.

A file belonging to another account answers the same 404: every lookup is scoped to the caller.