Skip to content

Attach files to a record

A record often needs a document: the receipt for an expense, the minutes of a meeting, a signed consent form. A file column holds one document for each record. The person attaches it in the record’s form and downloads it from a list or from the form.

Declare the column in the table. This table keeps a receipt for each payment.

table payments "Payments" {
display: due, paid_on
due ref(dues) required "Due"
amount money required "Amount" { min: 0 }
paid_on date "Paid on"
receipt file "Receipt"
}

Without a block, the column takes a PDF or a photograph in the JPEG, PNG or WebP format, of at most 10 MB. Narrow it with accept: and max_mb:, one property on each line.

minutes file required "Minutes" {
accept: pdf
max_mb: 20
}

A required file column needs a document before the record can be saved. The compiler also refuses a page whose forms declare more than 63 MB of uploads together. See file.

The form of the table draws a file input for each column in fields:, including the file column.

page payment "Payment" {
route: /payments/{id}
new_route: new
access: manage_money
form of payments {
fields: due, amount, paid_on, receipt
}
}

The form writes a hint under the input: the accepted types, the size, and that a PDF is stored as it is. A phone offers the camera, the photo library and the files. The input has no capture attribute, so a person can also choose a PDF that is already on the phone.

Put the column in the columns: of a report or a list. Each row shows the name, the type and the size, and the name downloads the file.

report of payments {
columns: due, amount, paid_on, receipt
row -> payment
}

A region that names its columns must name the file column, or the download address of the region answers 404. A person who cannot see a row also gets 404 for its file.

A form that edits a record shows the file of that record, to the people the form admits. A form that creates a record shows no file, because the record does not exist yet. A student who starts a hand-in on a page with a file column in the form cannot download the hand-in of another student from its address. The student can download the hand-in on a page that shows it, such as the list of the student’s own hand-ins.

A page that finds its record by an unguessable token, such as a preview link, shows the files of the record that holds the token. The page adds the token to the address of each file of that record, as ?mtd_token=<token>. The files of other records that the same page lists get no token. The address of the file without the token gives 404 to everybody the page admits, also for a draft that the page shows. A published record stays readable through the pages that show it to everybody.

An image inside a Markdown text is an address that you typed. The page shows it as you typed it and never adds the token. A reader sees such an image only where another page shows that picture to the reader.

A file column holds one document. For several documents, make a table of documents that points at the record.

table attachments "Attachments" {
display: title
payment ref(payments) required "Payment"
title text required "Title"
file file required "File"
}

Show the documents of a payment with a list region on the payment’s page, and give the table its own form page to add one.

The engine reads the type of a file from its bytes. A file called receipt.pdf that holds a web page is refused, and so is a PDF that stopped in the middle of the upload. Each refusal is a message next to the input, and the rest of the form keeps what the person typed. The person chooses the file again.

A photograph loses its position and its camera data, because the engine stores it again as a JPEG or PNG. A PDF keeps everything it contains.

The engine does not scan files for viruses. Read A file is downloaded, never displayed before you accept files from people you do not know.

Pictures and files share one storage quota, 512 MB for each organization by default. The administration page at /matterdata/usage shows the two on separate lines. A file that a save replaces is not counted at once, and the nightly clean-up removes its bytes a day later.

Website privacy policy