previewUrl
previewUrl, function
def pure previewUrl(path: text): text
def const pure previewUrl(hash: text, path: text): text
Returns a URL that opens a file preview.
With path alone, the URL opens the latest version of the file at that path
in the Lokad file explorer. The version is resolved when the link is opened,
not when the script runs. The same link therefore follows subsequent updates
to the file.
With hash and path, the URL opens the specific version identified by
hash. In this overload, path supplies the displayed file name; its
extension must match the file type (for example, .csv or .ion).
hash: the file hash in Lokad storage.path: the file path to resolve, or the display path for the hash overload.
Examples
The following table links to the latest versions of two reports. The files must exist at the specified paths when the links are opened.
table Reports = with
[| as Name, as Path |]
[| "Orders", "/Reports/orders.csv" |]
[| "Inventory", "/Reports/inventory.csv" |]
show table "Latest reports" with
Reports.Name { href: #[previewUrl(Reports.Path)] }
To link to a fixed version, supply its hash instead. Replace the placeholder below with an actual file hash:
hash = "0123456789abcdef"
url = previewUrl(hash, "/data/items.csv")
show scalar "Preview url" with url
Remarks
The hash overload can be evaluated in a const context;
the path-only overload cannot. This function cannot be executed on
try.lokad.com.