How-to guides

Files and storage

The instance folder

Context.StorageDirectory is the instance's own, persistent folder (on Linux /var/lib/kofa/instances/<id>/). Write here everything that has to survive a restart: a recorded dataset, a trained model, a cache.

The folder can be browsed and downloaded (a folder as a zip) in the Files panel of the instance page, and with the Operator role uploaded to and deleted from. This is how a recorded dataset gets out and, for example, a model gets in; the Komod only has to watch the file. An upload is atomic: it is first written under a temporary name, then renamed, so you never see a half-written file.

Upload from the Komod's UI

A Komod's own view can also upload a file into the instance folder:

await Kofa.UploadFileAsync(InstanceId, "maps", "map.pbf", stream);

It needs the Operator role, and the server's size limit applies.

JSON and hot unload

The data of a port follows KOFA's JSON convention (camelCase, enums as text). In your Komod's code do not use a reflection-based JsonSerializer with the default (static) options for your own types: the System.Text.Json cache would keep the package's load context alive, and the package could not be unloaded (a memory leak on update).

For your own JSON use Utf8JsonWriter and JsonDocument, or pass your own JsonSerializerOptions instance that you discard with the package. The arguments and results of commands are serialized by KOFA with per-package options.