Files
Upload a multipart file
/a/Files_upload
Accept one multipart file upload for CRM2, create its tenant file row, and update supported parent resource file lists.
When to use this endpoint
Use Files_upload from CRM2 drop zones sending multipart Filedata. Despite the plural name, one invocation processes one uploaded file.
Authentication and permissions
Normal API transport requires signed API-key fields or a logged-in CRM session and a tenant context. Session CSRF applies except for the dispatcher’s upload/download exceptions.
These handlers do not add general Files Add/Edit/Delete or file-owner role checks. UI visibility is not that protection. Configured team-scope entry checks are separate and may validate the linked record and its Edit permission before a handler runs; see the route-specific note below. This does not introduce CRM2 role requirements for ordinary CRM1 requests.
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. It requires a supported type_enum and visible type_id: 0 Customer, 2 Asset, 3 Job, 4 User, 13 Task or 14 Contract. Upload/deleteAll additionally require the owning object’s Edit grant.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
Filedata | Multipart file | Yes | Uses the uploaded temporary path and client filename. Multiple browser files are sent as separate requests by the widget. |
type_id | Integer-compatible | Yes | Linked resource ID; presence is checked but zero is accepted. This is the linked object ID, never the file ID. |
type_enum | Integer-compatible | Effectively yes | Linked resource type; omitted becomes zero. Common verified values are 0 Customer, 1 Asset Type, 2 Asset, 3 Job, 4 User, 5 recurring Job, 6 User photo, 7 report-design image, 8 Job form photo, 9 report PDF background, 10 private/non-downloadable, 11 form file, 12 Quote, and 13 Task file. Other modules use later values; use the enum already emitted by the relevant CRM workflow. |
unique | Integer-compatible | No | Truthy stores the new file first, then deletes earlier live files for the same type/resource through the normal lifecycle. |
Example request
// multipart/form-data
Filedata=@asset-photo.jpg
type_enum=2
type_id=1042
Example response
{
"ok": 1,
"id": 4821,
"url": "files/2/1042/7d4f..."
}
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":"no file uploaded"} | The multipart file collection is empty. |
{"error":"missing or invalid parameter: type_id"} | Type-ID key is absent. |
{"error":"file too large. max file size is 12582912 bytes"} | Content exceeds 12 MiB. |
{"error":"failed to store file"} | The storage helper returns a falsy result. |
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 storage helper inserts metadata with uploader ID and updates legacy file lists for Customer, Asset, Job, User, and recurring-Job types. This wrapper additionally rebuilds Customer/Asset lists.
- With
unique=1, previous files are soft-deleted with content cleanup and deletion logs only after the replacement is stored. There is no cross-file transaction, content-type allowlist, filename normalization, or resource-existence check. - No pagination applies to this write. Use a fresh metadata/list read before dependent work; an error after storage, audit or notification work does not imply that earlier steps were rolled back.
- The storage URL is files/
/ / . The returned id is the separate new file-record ID, url is tenant-relative, and filename remains the supplied display name. None of those values is the parent resource ID returned in the URL’s third segment. - The configured FILESLIB_MAXSIZE limits decoded bytes (default 12 MiB); PHP/webserver request limits may reject the request earlier. Base64 and multipart transport overhead are separate from this stored-byte limit. The route has no idempotency token; repeating a successful request normally creates another file.
Side effects
- Stores bytes and metadata, stamps creation/edit/access fields, invalidates files cache and refreshes supported parent file lists/User history through the shared storage library. Job outsourcing can propagate linked file identifiers. unique cleanup runs after storing the replacement and is not part of a rollback-safe batch.
See it in Fieldmotion
CRM1
No primary CRM1 caller was found; CRM1 data-URI widgets use File_upload.
CRM2
Upload files on Customer, Job, Asset, User, Asset Type, photo, support, and shared file drop zones.
Related endpoints
File_uploadalso accepts data URIs.File_getMaxUploadSizeexposes the limit.- File identifiers and downloads explains file ID, resource ID, type enum, stored URL and the different content response shapes.