6.2.3 File Uploads
| (require congame-web/components/uploaded-file) | |
| package: congame-web | |
This module provides functions for handling file uploads in studies running on the Congame server.
procedure
(upload-file! binding [#:prefix prefix]) → uploaded-file?
binding : binding:file? prefix : (or/c #f string?) = #f
The binding argument should be a file binding from a form submission (typically obtained from an input-file field).
If prefix is provided, it is prepended to the original filename with a hyphen separator. This is useful for organizing uploaded files or adding participant identifiers.
struct
(struct uploaded-file (key filename content-type))
key : string? filename : string? content-type : string?
The key field is a unique identifier used internally to retrieve the file. The filename field contains the original filename (potentially with a prefix added). The content-type field contains the MIME type of the uploaded file.
procedure
(uploaded-file-attachment file label) → xexpr?
file : uploaded-file? label : string?
The label argument specifies the display text for the attachment link.
procedure
(valid-pdf? binding) →
(or/c (cons/c 'ok binding:file?) (cons/c 'err string?)) binding : binding:file?
Returns (cons 'ok binding) if the file’s content-type is "application/pdf", or (cons 'err "the file must be a PDF") otherwise.
Use this with the #:validators argument of input-file to restrict uploads to PDF files only.