Osy#betaRun it on Osyrin: osyrin.com

Reference / Storage

Uploading a large file in parts — resumable, onto a row's attachment

A file larger than the single upload's 10 MB — a run's log, a transcript, a recording — is sent in parts of at most 32 MiB to `/api/files/uploads` (or the MCP tools `start_file_upload`, `upload_file_part`, `finish_file_upload`). An interrupted sender resumes with the parts it still has to send. The upload ends as a FileAsset on a row's `[Attachment]` field, or as a new version of a file, under the same rules as a single upload.

preview1 example compiled by CIstoragefilesuploadsapi

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.

stepRESTMCP tool
start, or resumePOST /api/files/uploadsstart_file_upload
put part n (numbered from 0)PUT /api/files/uploads/{id}/parts/{n}upload_file_part
finishPOST /api/files/uploads/{id}/finishfinish_file_upload
which parts are heldGET /api/files/uploads/{id}start again with uploadId
give upDELETE /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 security rules, any except 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 answers 404.
  • 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 partat most 32 MiB (16 MiB when you name none) — well under a proxy's 100 MB / 100 s request bound
partsat most 10 000
the filethe organisation's files.maxBytes, else 1 GiB
an open upload24 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#

Related

[Attachment] — a file readable wherever its row is

`[Attachment]` on a `FileAsset` reference makes the file readable by exactly the people who may read the row holding it…

A file's history — supersede, and what each version keeps

Replacing a stored file's content while keeping what it said before. The FILE is the identity — a record pointing at it…

Files (addressing something the app stores)

The platform stores a file two ways, and which one you hold decides how you address it. A PATH-keyed file lives at an…

publishing a REST API (app.Apis)

`app.Apis` publishes your app to a third party over HTTP. You never write a controller or an endpoint handler — you…

Your organization's policy: what each kind of rule affects, what its refusal says, and how to ask

An organization can set rules its applications keep: the outbound hosts they may reach, the package versions it…