public_link
public_link
Makes an address that opens one stored file or image for ANYONE who has it, without a session: the way to put a
file in a mail or a message to someone who does not use the app (a customer's photo, a PDF summary).
The url, midsize_url and thumbnail_url of a stored file or image open only for the session the object was
handed to; public_link is the one way to make an address for an outsider.
The address carries an expiry time and a signature made with a secret of the app. Nobody can change the file
it names or its expiry, and it stops working when it expires or when the file is deleted. It cannot be
withdrawn sooner, so make a link only for a file that may be seen by whoever the address reaches, and give it
the shortest life that serves.
Runs on: the server only. The statement that calls it runs on the server, and its result is a server-side value: the server keeps it, the device never writes it, and it is copied to the device only when a device statement reads it.
A link works only on the app that made it
A link made in the preview of an app does not open on the app once it is deployed to a host of its own, nor the reverse: each has its own secret and its own files.
Formats:
link = public_link(file)
link = public_link(file, days)
link = public_link(image, days, size)
Parameters:
| Parameter | Type | Description |
|---|---|---|
| file | cloudobject | the stored file or image: what fileprompt, imageprompt or store_file returned, or a field of a record that holds it |
| days | number |  [Optional]how long the address works, in days (default 30, at most 365; a fraction is allowed: 0.5 is twelve hours) |
| size | string |  [Optional]for an image, which of its three sizes: "full" (the default), "midsize" or "thumbnail" |
Returned Value:
| Type | Description |
|---|---|
| string | the complete address (https://...), ready for a mail; an empty string when the link could not be made (a runtime error says why) @Server Side Only |
Examples
photo_link = public_link(job.before_photo, 30)
send_mail(job.cust_email, "Your work order", concat("Before: photo
"), from_address, true)
thumb = public_link(job.before_photo, 7, "thumbnail")