All guides Backups and undo: getting an earlier version of your app back Files and images your app's users upload: taking, storing, showing and sharing them Plans and limits: how many projects you can have, the Exotool notice, and what happens at the limit Resources: connecting an Exotool app to outside services Sign-in and permissions: users, logging in and who may do what in your app Storing data: objects, sets and where your app keeps them Taking payments: cards, charges and holds with Stripe or PayPal
Files and images your app's users upload: taking, storing, showing and sharing them
This guide is for the person whose app lets its users add a photo or a file while the app runs: a picture of a job, a profile photo, a PDF, a document. It covers how the app asks for the file, what it gets back, how to keep it on a record, how to show it, who is allowed to open it, how to give it to someone outside the app, and what changes in a deployed app.
Contents
- Two kinds of files: the users' and the design's
- Asking for a photo or a file
- What comes back: a stored image or a stored file
- Keeping an upload on a record
- Storing a file the app made: store_file
- Showing an image and offering a file
- Who can open an upload: the access rule
- Giving a file to someone outside the app
- Uploads in a deployed app
- When something does not work
1. Two kinds of files: the users' and the design's
Two different things are both called "uploading". This guide is about only one of them.
| Files of the design | Files of the app's users (this guide) | |
|---|---|---|
| Who adds them | You, the builder, in the editor | The people using the app, while it runs |
| Examples | The app icon, the background image, a logo, a brochure used in a screen | A photo of a job, a profile picture, a PDF a user sends in |
| What they are | Part of the app's design, served to every visitor | Data: a record in the app's database |
| Who can open them | Everyone who opens the app | Only a session that was handed the record (section 7) |
Files of the design are covered in the editor reference, in the section "The app icon, background, and media". Nothing in this guide applies to them, and an uploaded photo of a user is never copied into the design.
2. Asking for a photo or a file
Two functions of the Exotool language ask the user for a file. Both take no arguments, and you write them in an activity, for example in the Do On Action of a button.
| Function | What the user sees | What it returns |
|---|---|---|
imageprompt() |
A drop zone plus a file picker for an image. On a phone the picker offers the camera and the photo library, so the dialog varies with the device | A stored image (section 3) |
fileprompt() |
A drop zone plus a file picker for a file | A stored file (section 3) |
photo = imageprompt()
if (photo) {
alert("Thank you, the photo was saved.")
}
When the user cancels, or the upload fails, the function does not give a stored object, so
test the result before you use it, as above. On a failure an alert with the error is shown to
the user, without any code of yours, and the variable upload_error is set to the text of the
error. upload_error is a name the app itself uses: do not use it for a variable of your own.
fileprompt() accepts a file whose name ends in one of these extensions: pdf, txt, csv, json,
xml, html, css, js, svg, png, jpg, jpeg, bmp, ttf, woff, mp4, mp3. Another kind of file is
refused. This guide does not state a largest size for an upload, because the reference
documents do not give one.
3. What comes back: a stored image or a stored file
An upload becomes a cloud object: a record kept in the app's database, like the other
data of the app. The bytes of the file are kept in the database too, and they are removed when
the object is deleted with delete(...).
imageprompt() returns a stored image (type storedCloudImage). The app makes three sizes
of the picture by itself: the full size, a mid-size and a thumbnail. fileprompt() and
store_file(...) return a stored file (type storedCloudFile).
| Field | Stored image | Stored file |
|---|---|---|
url |
The address of the full-size image | The address of the file |
midsize_url, thumbnail_url |
The addresses of the two smaller sizes | - |
original_filename |
The name of the file as it was uploaded | The file's name, with its extension |
extension, mime_type |
- | For example pdf and application/pdf |
size |
- | The size in bytes |
last_modified_time |
When it was stored, as a Unix time stamp | The same |
The addresses in these fields are not ordinary web addresses: read section 7 first.
A stored object is a record like any other, so you can give it fields of your own:
image.itemtitle = image.original_filename.
4. Keeping an upload on a record
An upload usually belongs to something: a photo to a job, a document to an order. Put the stored object itself in a field of that record:
photo = imageprompt()
if (photo) {
job.photo = photo
}
Keep the object, never one of its addresses. job.photo = photo is right;
job.photo_address = photo.url is wrong, for the reason given in section 7.
To remove an upload, delete the object: delete(job.photo). The file's data goes with it.
5. Storing a file the app made: store_file
store_file(file_name, content [, mime_type]) stores a file that the app made on the
device, with no dialog: a PDF it built, a CSV it assembled, a text. It returns a stored file,
exactly like fileprompt(), or false with upload_error set (and an alert shown).
file_name: the name to store the file under. Its extension must be one listed in section 2.content: a string (text), adata:URL (the output of a PDF library or of a canvas), a Blob or File from a JS block, or an ArrayBuffer.mime_type: optional, the content type when the content is a string or an ArrayBuffer, for example"text/csv". A string without one is stored as plain text.
report = store_file("orders.csv", csv_text, "text/csv")
if (report) {
order.report = report
}
store_file runs on the device. Use it when the app itself produces the file.
6. Showing an image and offering a file
Show an upload from the fields of the stored object, in a template. A template is the HTML
of an element, with placeholders in double braces. In the item template of a list whose items
are stored images, write <img src="{{thumbnail_url}}">. In the item template of a list of
records that each hold a stored image in the field photo, or a stored file in the field
pdf:
<img src="{{photo.thumbnail_url}}">
<a class="external" target="_blank" href="{{pdf.url}}">PDF summary</a>
The second line is how the sample app "applib_076_field_service" offers a stored PDF: a link
that opens the file in a new tab. Use thumbnail_url in lists and midsize_url or url
where one picture is shown large.
Never copy an address into the design: not into a constant, not into an image of the design, not as text typed into a template. It would stop working (section 7).
7. Who can open an upload: the access rule
A session is one person's use of the app on one device, from opening it to leaving it.
The address of a stored file or image works only for the session the object was handed to.
When the server sends a stored object to a device, the address in its url fields carries a
token of that session. The server serves the file only when the address carries the token of a
live session that was handed that object. An address with another id, or without the token,
opens nothing.
What follows from this:
- Never store an address in a field, and never send one to another user or put one in a mail. It works for whoever holds it, but only while that one session lives.
- An address read on the server opens nothing at all. A
urlread in server code, for example while composing a mail, has no token in it. So a mail that containsphoto.urlholds a dead link. - To show one user's upload to another user, hand them the object. Keep the object in a
field of the record it belongs to (section 4), and let each device receive that record
through a cloud set or a list built from one. Each device then gets the object with an
address of its own session, and
{{photo.thumbnail_url}}works for each of them.
Which users receive which records is decided by the cloud sets of your app; the language reference explains this under "Where code runs, where values live".
8. Giving a file to someone outside the app
Someone outside the app, such as a customer reading a mail, has no session. There are two ways to give such a person a file.
A public link
public_link(file [, days [, size]]) makes an address that opens one stored file or image
for anyone who has it, without a session.
| Argument | What it is |
|---|---|
file |
The stored object: what fileprompt, imageprompt or store_file returned, or a field that holds one |
days |
How long the address works. 30 by default, 365 at most. A fraction is allowed: 0.5 is twelve hours |
size |
For an image: "full" (the default), "midsize" or "thumbnail" |
It returns the complete https:// address. When the link cannot be made it returns an empty
string and a runtime error says why. It runs on the server only.
link = public_link(job.pdf, 30)
result = send_mail(job.cust_email, "Your summary", concat("<a href=\"", link, "\">PDF summary</a>"), from_address, true)
What to know about a public link:
- It is signed with a secret of the app. Nobody can change which file it names or when it ends.
- It ends at its expiry, or when the file is deleted. It cannot be withdrawn sooner in any other way.
- Anyone the address reaches can open the file. Make a link only for a file that may be seen by whoever receives it, and give it the shortest life that serves.
A mail attachment
send_mail(to, subject, body, from [, html_format] [, attachments]) can carry files.
attachments is a stored file (what fileprompt or store_file returns) or a list of them.
Each is attached under its name and type.
report = store_file("summary.pdf", pdf_data_url, "application/pdf")
if (report) {
result = send_mail(customer_email, "Your summary", "Your summary is attached.", from_address, true, report)
}
The attachments of one mail may be 8 MB at most, all together. Above that, send_mail
returns an error string and no mail is sent. send_mail returns "OK" or an error string, so
test the result. It needs an E-mail Server resource on the project; the guide on resources
explains that.
An app built before 24 November 2026 refuses a stored file as an attachment until it is built
again: save the project once. For a photo from imageprompt(), send a public link; attachments
are for stored files.
9. Uploads in a deployed app
- The uploads are data. They live in the app's database: in the app's
backend/datafolder on the host, or in MySQL when the project uses a MySQL resource. A new deployment replaces the app's files and leaves the data alone. - What the host needs. PHP's
gdextension, for the images people upload, and a writablebackend/datafolder and a writableimgfolder. The deployment guide lists the rest. - Public links belong to one installation. The app keeps the secret that signs its public
links in the file
backend/data/public_link_secret.php. It makes the file at the first use. The file is not part of what a deployment sends, so an app deployed to your own host makes its own secret. That is why a link made in the preview does not open on the deployed app. - Keep that file. A redeploy leaves it alone. When you move the app to another host, move
it with
backend/data: without it, the links already sent out stop working. To end every public link at once, delete it. - In an iOS app made from your project, uploads work: the picker offers the photo library, files, and on a device the camera.
10. When something does not work
| What you see | Likely cause | What to do |
|---|---|---|
| An image shows for the user who uploaded it and is broken for everyone else | Its address was stored in a field or sent on; an address works for one session only | Store the object (job.photo = photo) and show it from the object's fields: {{photo.thumbnail_url}} |
| A link to a file in a mail opens nothing | The mail holds the object's url, read on the server, which carries no session |
Use public_link(file, days) for the address, or attach the file with send_mail |
public_link returns an empty string |
The value is not a stored file or image; days is 0 or less; the size is not "full", "midsize" or "thumbnail"; or the app cannot write to its backend/data folder |
Read the runtime error, which names the cause; pass the stored object itself; on your own host make backend/data writable |
| A public link made while testing does not open on the deployed app | The preview and the deployed app each have their own secret and their own files | Make the link on the app that holds the file |
| Every public link stopped working after a move to another host | backend/data/public_link_secret.php was not moved |
Move the file with backend/data; links made after the move work in any case |
| A public link should stop working now | A link cannot be withdrawn before its expiry | Delete the file; or delete public_link_secret.php, which ends every link of the app |
| The upload is refused | For fileprompt or store_file: the file's extension is not in the accepted list |
Section 2 has the list; store_file also needs a file name with an extension |
| An alert appears after a failed upload although your code shows none | imageprompt, fileprompt and store_file show the error themselves |
Nothing; do not add a second alert for upload_error |
send_mail returns an error about 8 MB |
The attachments of the mail are larger than 8 MB together | Send a public link in place of the attachment |
send_mail returns "an attachment must be a stored file" |
What was passed is not a stored file, or the app was built before 24 November 2026 | Pass what fileprompt or store_file returned, or a list of them; save the project to build it again |
| Images cannot be uploaded on your own host | The host lacks PHP's gd, or the img or backend/data folder is not writable |
See the deployment guide, "What is sent, and what the host needs" |