Summary#
A single upload (POST /api/files/upload) takes at most 10 MB and is held in memory while it is stored. A larger
file goes in parts: start the upload, put each part, then finish. The platform checks each part's size and SHA-256
as it arrives, joins the parts on disk (never in memory) when you finish, checks the whole file's size and SHA-256,
and only then makes the file.
The file lands on a row's [Attachment] FileAsset field, or becomes the next version of a file. Your Osy# code
reads it like any other file:
using Osysharp.Storage;
[Principal] entity User { [Required, MaxLength(200)] string Email; }
entity Run {
[MaxLength(200)] string Title = "";
[Required] User Owner;
[Attachment] FileAsset? Log;
security {
allow read when IsAuthenticated;
allow create, update where Owner == user;
}
}
/// The run's log as its owner's host uploaded it: name, size and the bytes themselves.
[Authorize(IsAuthenticated)]
public string LogSummary(Run run) {
var withLog = Run.Where(r => r.Id == run.Id).Include(r => r.Log.CurrentVersion).First();
if (withLog.Log == null) { return "no log yet"; }
var bytes = File.ReadAllBytes(withLog.Log);
return withLog.Log.Name + " · " + Text.ByteSize(withLog.Log.CurrentVersion.Size ?? 0) + " · " + bytes.Length + " bytes read";
}Description#
The three steps#
All three take the app's bearer ticket or API key, exactly as POST /api/files/upload does.
| step | REST | MCP tool |
|---|---|---|
| start, or resume | POST /api/files/uploads | start_file_upload |
| put part n (numbered from 0) | PUT /api/files/uploads/{id}/parts/{n} | upload_file_part |
| finish | POST /api/files/uploads/{id}/finish | finish_file_upload |
| which parts are held | GET /api/files/uploads/{id} | start again with uploadId |
| give up | DELETE /api/files/uploads/{id} | — |
Start names the file and where it goes:
{
"fileName": "run-4711.log", "mimeType": "text/plain",
"totalBytes": 157286400, "sha256": "<the whole file's SHA-256, hex>",
"partBytes": 16777216,
"target": { "entity": "Run", "id": "<the run's id>", "field": "Log" }
}For a new version of an existing file, the target is { "fileAssetId": "<the file's id>" }. The answer carries the
uploadId, the partBytes and partCount, the parts already held, and expiresAt.
Put each part as the raw request body, with its own SHA-256 (lower-case hex) in the X-Osyrin-Part-Sha256
header. Every part but the last is exactly partBytes. A part sent twice is harmless.
Finish joins the parts. It answers { fileAssetId, version, name, mimeType, size, sha256, url }; when parts are
missing it answers 409 with missing: [3, 7], and nothing is lost — send those and finish again.
Resuming#
Send the same start again with "uploadId": "<id>". If it is still open, the answer's held lists the parts the
platform has, and you send only the rest. An upload whose manifest differs (another size, hash, name or target) is
409; one that finished, was abandoned or expired is 404 — start afresh.
The rules — the same as a single upload#
Every rule a single upload meets is checked when the upload starts, before any part is kept, and again when it finishes:
- The write rule. Setting the field must be a write the caller may make: the row's
securityrules, anyexcept via, and the attachment rule (only the file's owner may attach it — the uploader is). A new version needs the file's own write rule. A row or file the caller cannot read answers404. - The storage quota. The whole size is charged at start; an upload that would pass the app's cap is
507. - The organisation's largest file,
files.maxBytes(see Your organization's policy: what each kind of rule affects, what its refusal says, and how to ask):413, saying the limit. With no rule a file may be at most 1 GiB; a rule may set any maximum up to 5 GiB. It holds for every file write — a single upload,File.Create,File.Supersede— not only for this one.
An upload is its starter's: a part, finish or status from anyone else answers as an upload that does not exist.
Limits#
| a part | at most 32 MiB (16 MiB when you name none) — well under a proxy's 100 MB / 100 s request bound |
| parts | at most 10 000 |
| the file | the organisation's files.maxBytes, else 1 GiB |
| an open upload | 24 hours from its start; after that its parts are reclaimed and its id answers 410/404 |
An SVG is sanitised as it is stored, so it is sent in one request. File contents never reach a log or a trace.
See also#
- [Attachment] — a file readable wherever its row is — who may read and attach a file held by a row
- A file's history — supersede, and what each version keeps — a file's history, which a parted upload can add to
- Files (addressing something the app stores) — the two ways the platform stores a file
- publishing a REST API (app.Apis) — the app's REST door and its credentials
- Your organization's policy: what each kind of rule affects, what its refusal says, and how to ask —
files.maxBytesand the organisation's other rules