Summary#
There are two stores, and the first thing to know is which one you are holding.
| what you have | how it is addressed | shown with |
|---|---|---|
a path — "public/logo.png", an upload result | File.Url(path) · File.SignedUrl(path) | Image(src: File.Url(path)) |
a FileAsset — a row, from File.Create or Image.Thumbnail, or a FileAsset field | it has no path; the platform addresses it | Image(fileAsset: row.Photo.Id) — see Showing a picture on a page |
⚠ The verbs on this page take a path string. A FileAsset carries none, so File.Url(asset) and
File.SignedUrl(asset) do not exist and the compiler refuses them — that is the commonest first-day mistake, and
Showing a picture on a page is what you wanted.
Within the path store, a stored file is addressed by URL, and which URL you ask for is an access decision.
using Osysharp.Storage;
[Principal] entity User { [MaxLength(200)] string Email; }
entity Item { [Required, MaxLength(200)] string ImagePath; }
// Anyone may fetch this — it is an asset, served to whoever asks.
string PublicImage(Item item) { return File.Url(item.ImagePath); }
// This one belongs to somebody, so the URL carries its own expiring grant.
string PrivateReport(User user) { return File.SignedUrl("reports/" + user.Id + "/q3.pdf"); }Description#
File.Url is pure sugar over the serving route — an app-relative path becomes /_osy/files/…, which
means it works directly inside a render argument. It grants nothing: what it addresses is served to whoever asks,
so it is right for assets and wrong for anything a person owns.
File.SignedUrl is the other case, and it is the one to reach for by default when the file belongs to somebody: the URL carries its own time-limited grant, so sharing it is a decision with an expiry rather than a permanent one.
See also#
- Showing a picture on a page — putting a picture on a page, from either store
- File.Url — the public address of a PATH, and where it is safe
- File.SignedUrl — a time-limited grant to one caller, over a PATH
- Image.Thumbnail, Resize and Convert (a stored image, transformed) — a stored image transformed:
Image.Thumbnail,Resize,Convert, each a newFileAsset