Skip to content

Uploads

Edgar Mesquita edited this page Nov 25, 2026 · 5 revisions

Uploads

🌐 This page in: English · Português · Español · Français · Deutsch

Files a person sends to the app's own server: a 3D model to print, a PDF to attach, a spreadsheet to import. The app declares what it accepts once, in C# that the page and the server both read, drops a FileUpload on the page, and receives each file in a Server Action as an UploadedFile it reads as a stream. Everything between, the parts, the progress, a connection that drops, a page that is reloaded halfway, is the SDK's.

Since 0.2.0-preview.66

What the app accepts

public static class Uploads
{
    public static readonly UploadPolicy Models = new("models",
        filters: [new FileFilter("3D models", "stl", "obj", "3mf")],
        maxSize: 250 * 1024 * 1024);
}

A policy has a name the server knows it by, the formats it accepts (an empty list accepts any file) and the largest file it takes. requireSignedIn: true keeps it for signed-in people.

The server accepts the policies the app names in Program.cs, and MapUI() maps the endpoint the page sends to:

builder.Services.AddUI(ui => ui.UseUploads(uploads => uploads.Accept(Uploads.Models)));

The policy is the rule on both sides. The page asks policy.RefusalOf(name, size) before it sends a byte, and the server asks the same rule again, in the same words, whatever the page let through: "Only .stl, .obj, .3mf files are accepted here.", "The file is larger than the 262144000 bytes accepted here." A refusal from the server (a policy it does not accept, a visitor under a policy that requires a signed-in person, too many unfinished uploads) reaches the page as its short English reason.

A page that takes files

[Page("/models")]
public sealed class ModelsScreen : StatefulComponent
{
    private string _saved = "";

    [ServerAction]
    public async Task<string> SaveModel(UploadedFile model)
    {
        await using var content = await model.OpenRead();
        // … store it where the app keeps its data …
        await model.Delete();
        return model.Name;
    }

    public override VisualNode Build(ComponentContext context) =>
        Column(gap: Space.S4, children: [
            FileUpload(Uploads.Models, onCompleted: model => _ = Save(model)),
            Text(_saved, TypeRole.BodyM),
        ]);

    private async Task Save(UploadedFile model)
    {
        var name = await SaveModel(model);
        SetState(() => _saved = $"Saved {name}");
    }
}

FileUpload draws an area files are dropped on, a button that asks the person for them (the way in for a keyboard and a screen reader), and a row for each file with its progress, its state, Pause, Resume, Cancel and, when it failed, why. What arrives or fails is announced. Its words are the SDK's, in every culture the SDK ships; label: and hint: replace the invitation and the line that says what the area accepts. multiple: false takes one file at a time.

onCompleted receives each file once its last byte arrived. The page hands it to its own Server Action, and the server binds the parameter from the upload's id alone: the name, type, size and policy are the ones it recorded when the upload started, whatever the page sent beside the id. It binds the file only for the person who uploaded it, and only once it is whole.

OpenRead streams the content from where the server keeps it, and Delete removes it. Both are the server's ([ServerOnly]): client code that calls either is refused at the build (EQ2010).

How a file travels

  • In parts of 8 MB, each answered before the next is sent, so the progress moves inside a part and no request comes near the 30 MB a server takes in one by default.
  • Three at a time. A page sends three files at once, and the others wait their turn, Waiting, in the order they were chosen. Its first creation goes alone, since the server's answer to it is what names a visitor's browser. A creation refused because the person already has as many unfinished uploads as MaxUnfinished allows waits as long as the server says (Retry-After) and asks again, for up to ten minutes.
  • A part that fails is sent again, after a pause that grows (0, 1, 3, 5 and 10 seconds), from the offset the server says it holds. Past the last pause the upload fails with "The connection to the server was lost."
  • A reloaded page goes on. The upload's address is remembered in the browser under the file's name, size, date and policy: choosing the same file again asks the server how much of it arrived and sends the rest. A file whose area leaves the screen pauses, and goes on the same way.
  • Cancel removes it, on the server too.

The protocol is tus 1.0, spoken by the browser's runtime and by the server; no page names it.

Where the server keeps them

{
  "EQuantic": {
    "Uploads": {
      "Folder": "uploads",
      "Expiry": "1.00:00:00",
      "MaxUnfinished": 5,
      "MaxUploadsPerOwner": 100,
      "MaxBytesPerOwner": 1073741824,
      "MaxTotalUploads": 10000,
      "MaxTotalBytes": 10737418240
    }
  }
}

The folder is a staging area: every upload, finished or not, is removed when its expiry passes, so the Server Action stores what it received where the app keeps its data. Without Folder the server uses a folder of its own under the system's temporary folder, and logs which.

An upload belongs to whoever started it: the signed-in person, or the browser, by an HttpOnly cookie (eq-uploads). Nobody else continues it, reads its offset, deletes it or receives it in an action. A page of another site is refused, by the same rule and the same EQuantic:ServerActions:AllowedOrigins as the Server Actions.

Since 0.2.0-preview.68

What the server keeps is bounded, each person's and everyone's together, a finished upload counted until it expires: MaxUploadsPerOwner (100) and MaxBytesPerOwner (1 GiB) for one person, MaxTotalUploads (10,000) and MaxTotalBytes (10 GiB) for the whole store. A browser that sends no cookie is a new person each time, so only the store's limits stop a script that never keeps one. An upload past a limit on uploads is refused with 429, past a limit on bytes with 413, each naming the limit.

The server says what each file is: its type is the one its extension names, as ASP.NET Core's static files read it, never what the device sent, and its name keeps no folder, no control character, no character a file system refuses, none of the names Windows keeps for its devices, and never . or ... A Folder under the web root stops the app at start, since the static files would serve every upload. The eq-uploads cookie is Secure but for plain HTTP to the machine itself or in Development, so an app behind a proxy that ends TLS writes it right without forwarded headers.

Several instances

Since 0.2.0-preview.73

The folder belongs to the instance that writes it. Behind a balancer, each part of an upload and the Server Action that receives it may reach another instance, so an app that runs several gives its uploads a storage they all reach: a class of its own over its object store, blob container, database or shared volume.

builder.Services.AddUI(ui => ui.UseUploads(uploads => uploads
    .Accept(Uploads.Models)
    .UseStorage<BucketUploadStorage>()));

BucketUploadStorage implements IUploadStorage and is registered as a singleton. It keeps each upload's record, a StoredUpload (its id, owner, policy, file name, type, size, start and expiry), and its bytes, through seven members: CreateAsync, FindAsync, LengthAsync, AppendAsync, OpenReadAsync, DeleteAsync and ListAsync. The server reads everything from it, whose an upload is, how far it arrived, the limits and the expiry, so every instance answers every request of an upload alike.

What a storage must hold to:

  • AppendAsync(id, offset, content) adds the content only when offset is the length it keeps, and otherwise keeps nothing and answers 0: two instances may each accept a part for the same offset. An object store writes each part as an object of its own and reads them in order; a database appends a row.
  • A part cut off may leave all, some or none of its bytes, in order, as long as LengthAsync answers what is kept: the page asks for it and sends the rest.
  • ListAsync is read on every creation, to count the limits, and every ten minutes, to remove what expired.

The server hands a storage only the ids it gives, 32 lowercase hexadecimal digits, and answers any other as an upload that does not exist. Across instances, creations that arrive at the same instant on different ones may each take the last place a limit allows.

Drawing your own

FileUpload is drawn over the IUploads capability, which a page takes to draw something else: one picture as an avatar, a progress in a toolbar.

public sealed class ModelButton(IFilePicker? picker, IUploads? uploads) : StatefulComponent
{
    private Upload? _upload;
    private IDisposable? _changes;

    protected override void OnUnmount() => _changes?.Dispose();

    public override VisualNode Build(ComponentContext context) => _upload switch
    {
        null => Button("Send a model", onPressed: () => _ = Choose()),
        { State: UploadState.Failed } failed => Text(failed.Error ?? "", TypeRole.BodyM),
        { State: UploadState.Completed } => Text("Sent", TypeRole.BodyM),
        var sending => ProgressBar((float)sending.Sent / sending.Size, label: "Sending the model"),
    };

    private async Task Choose()
    {
        if (picker is null || uploads is null) return;
        if (await picker.PickFileAsync(Uploads.Models.Filters) is not { } file) return;
        var upload = uploads.Start(file, Uploads.Models);
        _changes?.Dispose();
        _changes = upload.Subscribe(_ => SetState(() => { }));
        SetState(() => _upload = upload);
    }
}

Start answers at once with the Upload, which goes on by itself. Its State is Waiting, Sending, Paused, Completed, Failed or Cancelled; Sent and Size are its progress in bytes, Error why it failed, and Result the UploadedFile once it completed. Subscribe hears every change and answers an IDisposable, as INetworkStatus does, so a component ends it where it ends.

Since 0.2.0-preview.66

Where it is absent. Server rendering has no browser to send from, and the native shells have no transport yet: IsAvailable is false there, FileUpload draws the same area disabled, and Start answers an upload that has already failed, saying so. The browser enables the area when the page runs there.

Limits

  • Behind a balancer, the uploads need a storage every instance reaches (Several instances, above): the folder serves one instance.
  • A page on another domain also needs the app's CORS policy to expose the tus headers, which the SDK does not configure.

Clone this wiki locally