On this page:
upload-file!
uploaded-file
uploaded-file-attachment
valid-pdf?

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
Saves an uploaded file to the server and returns an uploaded-file record containing metadata about the stored file.

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?
A structure representing an uploaded file’s metadata.

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?
Creates an attachment X-expression from an uploaded file record.

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?
A validator function that checks if an uploaded file is a PDF.

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.