Files
Get base64 file content
/a/File_getFile
Return one file’s name, creation date, and base64-encoded bytes for client-side ZIPs and previews.
When to use this endpoint
Use File_getFile when client code must consume bytes without navigating away, such as CRM2 bulk downloads. Prefer File_get for a single browser download.
For the file-export integration, this route is the direct ID → filename + bytes option: decode fileData with strict base64 decoding, then use fileName as the original display name. The returned name is not a safe local filesystem path until the consuming integration validates it.
Authentication and permissions
Use signed API-key authentication or a logged-in CRM session on the account’s routed host. File IDs and stored URLs normally resolve within that tenant; they are not public or cross-tenant identifiers. Session CSRF applies where required by the dispatcher.
The shared content-read guard denies type 10. For ordinary file types it requires a user session; CRM2 sessions (crmVersion=2) additionally need Files View (pageFiles_view). CRM1 does not receive that CRM2 page permission check.
Types 6, 8 and 16 return before the shared guard’s login/Files-page checks. Types 7 and 9 bypass the CRM2 Files-page check only after a user is established; type 6 is also treated as an app asset. An internal shareable-file context can bypass the remaining ordinary checks. Explicit route login checks still apply, and these exceptions do not override the dispatcher’s configured record-scope guard.
When department/team or Assigned Jobs Only scope is configured for the actor, the dispatcher adds record-scope checks. This is selected by account features/actor flags, separately from the CRM2-only Files View check; the existing TeamAccess entry guard has no CRM-version condition. Explicit id/ids values are checked against visible file records. Other filename-only selections or mapped-filter-only bulk mutations can be rejected for lacking an explicit scoped selection.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Integer-compatible | Conditional | Positive file ID. Either this or at least one nonblank paramName is required. ID takes precedence. Use the tenant file-record ID returned by upload/list/detail calls. This is separate from type_id/typeId (the linked resource ID), and from the random token in a storage URL. |
paramName | String or native array | Conditional | Stored filename(s). Blank values are discarded; the first database match is returned with no explicit ordering. |
oid | Integer-compatible | No | Cross-tenant Job-file access, subject to the same outsourcing-link guard as File_get. |
return | Any | Internal only | Presence returns before constructing the normal response and therefore yields no useful file payload. |
Example request
$file = FM_api('File_getFile', ['id' => '4821']);
Example response
{
"fileName": "service-photo.jpg",
"fileData": "/9j/4AAQSkZJRg...",
"cDate": "2026-09-20 10:15:00"
}
Errors and unusual responses
| Response | Condition |
|---|---|
{"error":"not logged in"} | No authenticated tenant context is available. Invalid signed credentials can be rejected by the dispatcher before the handler runs. |
{"error":"missing or invalid parameter"} | Neither a positive ID nor a nonblank filename is supplied. |
{"error":"no such file"} | No non-deleted row matches. |
{"error":"permission denied"} | The shared read guard or outsourcing guard rejects access. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- The bytes are loaded from the current URL, with the same legacy URL/path fallbacks as
File_get, then base64 encoded. Missing storage bytes become an empty encoded string. - There is no pagination. The entire file is held and encoded in memory.
- Omitted id becomes zero; invalid/blank id may fall back to paramName if nonblank filenames are supplied. A positive id takes precedence. Native paramName lists are trimmed; JSON-encoded list text is treated as one filename. No linked-resource/type filter participates in filename lookup.
- The response keys are case-sensitive: fileName, fileData and cDate. They differ from File_getByUrl (filename/data/mimetype). There is no ok wrapper, MIME field or checksum here. Do not send return; its mere presence makes the handler return null after loading bytes.
Side effects
- Storage reads can update access/size metadata, restore archived bytes and clear archive linkage, or hydrate missing database bytes from a configured backend. File content reads are not guaranteed read-only. No email or user notification is sent by the ordinary successful download path.
See it in Fieldmotion
CRM1
No normal CRM1 caller was found; CRM1 generally navigates to File_get.
CRM2
Select multiple files for ZIP download, or open file/photo workflows that request content in JavaScript.
Related endpoints
File_getstreams the same content.File_getRequestedDetailsreturns metadata only.- File identifiers and downloads explains file ID, resource ID, type enum, stored URL and the different content response shapes.