Attachments and phone capture
Inspections need photos, deliveries need signed forms and repairs need the vendor's report. Attachment properties hold those files on objects. A person uploads a file, an action puts it on an object, and from then on anyone who may read that object may read the file, and nobody else. On a phone, a scanned barcode or QR code finds the object it belongs to, so a technician standing at a machine opens its record in one step
attachment for one file, attachments for a listIn the platform today
- Attachments and scan lookup run in the platform service
- A property of
type: attachmentholds one file id andtype: attachmentsa list, withacceptlimiting the content types POST /api/v2/filesuploads a file and returns its id, an action parameter of the same types takes it, and the file is attached when the action applies; files nothing attached withinfiles.keepUnattached(24 hours by default) are purged- Functions read files with
ctx.file(id)andctx.file_info(id) capture.scannames the property a scanned code is looked up by, throughGET /api/v2/capture/scan?code=- In the app, connected to the platform service, object panels show image thumbnails and files, action forms take a file or a photo from the phone's camera, and a Scan button reads a code with the camera where the browser can, or takes it typed in
- The platform never makes images or files itself: people upload their own
- An attachment property on the object type, and an action type with an attachment parameter whose rules put it there
- Permission to run such an action, for anyone who uploads
- For scanning, a property on each scanned type that holds the code printed on the label
Define attachment properties
objectTypes:
inspection:
properties:
# a list of file ids
photos: { type: attachments, name: Site photos, accept: [image/*] }
signedForm: { type: attachment, accept: application/pdf } # one file id
actionTypes:
add-site-photo:
name: Add site photo
objectType: inspection
parameters:
inspection: { type: object, objectType: inspection, required: true }
photo: { type: attachment, accept: image/*, required: true } # or attachments
rules:
- modify:
object: { parameter: inspection }
set:
photos:
append: [ { parameter: inspection, property: photos }, { parameter: photo } ]
files: { maxSize: 200MB, maxObjects: 10, keepUnattached: 24h } # the defaults
capture:
scan: { equipment: equipmentId, yard-item: yardItemId }
accepttakes content types, one or a list;image/*takes any image- The
appendoperand adds a value, or each value of a list, to a list, so a rule adds one photo to the photos already there - An attachment property can't be the key, a link's
via, a row policy property or sealed maxSizeis the largest file,maxObjectsthe number of objects one file may be on, andkeepUnattachedhow long an upload waits for an action
Upload, then attach
- Upload.
POST /api/v2/files, with the file in the multipart fieldfileor as the raw body with?name=, returns{id, name, contentType, size, sha256, status, expiresAt}. The file is temporary and only its uploader can read it. Only people who may run an action that takes a file can upload (FILE_UPLOAD_NOT_PERMITTED) - Run the action. The attachment parameter takes the id, and
acceptis checked (FILE_TYPE_NOT_ACCEPTED) - Attach. When the action applies, every file its edits newly put on an object is checked and marked attached as part of the same commit as the edits. A check, a dry run, or a refused or failed action attaches nothing, and the upload is purged when it expires
POST /api/v2/files?name=pump-seal.jpg
Content-Type: image/jpeg
<bytes>
POST /api/v2/actions/add-site-photo:run
{ "parameters": { "inspection": "INS-2207", "photo": "fil_01JBB2X4N6Q8R0T2V4W6Y8Z0A2" } }
- A file can be attached by the person who uploaded it, by whoever approves a proposal it was proposed with, or, once attached, by anyone who can read it, to put it on another object up to
maxObjects - A proposal keeps its files while it waits; they are purged once it is rejected or expires
- A file no object holds any more, because it was replaced or its object deleted, is kept so an undo can put it back, but nobody can read it until an object holds it again
Who reads a file
An attached file is read through the objects that hold it. Anyone who can read one of them may read the file: the type's access label, its row policy and the property not being hidden from them all apply. Every download is in the audit log as file.read
Lists each attachment property of the object with its files' metadata. GET /api/v2/files/{id}/content returns the bytes, images, PDF and plain text inline and anything else as a download
Everywhere else it is an id
Queries, SQL, the change feed, sharing and exports see file ids and nothing else. Filter on them like any value
{ "query": { "from": "inspection",
"where": { "photos": { "$has": "fil_01JBB2X4N6Q8R0T2V4W6Y8Z0A2" } } } }
{ "query": { "from": "inspection",
"where": { "signedForm": "fil_01JBB2X9C3D5E7F9G1H3J5K7M9" } } }
Python functions read the bytes with ctx.file(id) and the metadata with ctx.file_info(id), for a file the caller may read, as a whole file in memory up to maxSize
Storage
The bytes are kept under the lake's root in _files/, in the same bucket when the lake is in S3, and data branches share main's files
The platform records each file's id, name, content type, size, SHA-256, uploader, status (temporary, attached or purged), when it expires, the proposal holding it and the action log entry that attached it
Purging runs at most once a minute when someone uploads, and administrators can run it with POST /api/v2/files:purge
Scan a barcode or QR code
Finds the objects whose capture.scan property equals the code, across the scanned types or one named with type, as the caller reads them, at most 10. The answer is {code, matches: [{objectType, key, title, property}]}. A type the caller can't read, or whose scan property is hidden from them, is left out. GET /api/v2/capture returns the scan configuration for the types the caller can see
API
| Endpoint | Does |
|---|---|
POST /api/v2/files | Upload a file; returns its id |
GET /api/v2/files/{id} | The metadata |
GET /api/v2/files/{id}/content | The bytes |
DELETE /api/v2/files/{id} | The uploader removes a temporary file |
POST /api/v2/files:purge | Administrators: purge what is due now |
GET /api/v2/types/{type}/objects/{key}/attachments | An object's attachment properties with their files |
GET /api/v2/capture | The scan configuration |
GET /api/v2/capture/scan?code=&type= | Objects whose scan property equals the code |
Refusals carry reasons such as FILE_TOO_LARGE (413), FILE_TYPE_NOT_ACCEPTED, FILE_NOT_ATTACHABLE, FILE_ATTACH_LIMIT, FILE_IN_USE and TYPE_NOT_SCANNED, in the shape on error codes
Limitations
- Sealed attachment properties are delivered on request
- TypeScript functions read file ids, not bytes; reading bytes is for Python functions
- Attachments in comments are delivered on request; attach the file to the object instead