Module for Apostol CRM1.
FileServer serves files stored in the database (via the file module of db-platform) over HTTP using a direct URL. Access is controlled by user permissions. Requests must comply with the API access rules.
FileServer and PGFile are complementary modules. PGFile syncs files from the database to the local filesystem; FileServer serves those files over HTTP.
- An HTTP
GETrequest arrives at/file/<path>/<name>. - The module authenticates the request (Bearer JWT token, session-based authorization, or SID cookie).
- Paths under
/public/are served using a bot session — no user authentication required. - Fast path: If the file already exists on the local filesystem, it is served directly with the correct
Content-Type. - Slow path: The file record is fetched from the database via a PG query, base64-decoded, written to disk, and served (deferred response).
http[s]://localhost:8080/file/<path>/<name>
| Parameter | Required | Description |
|---|---|---|
<path> |
Yes | File path |
<name> |
Yes | File name |
Fetch a file:
GET /file/doc/report.pdf HTTP/1.1
Host: localhost:8080
Authorization: Bearer <access_token>Fetch a public file (no auth required):
GET /file/public/logo.png HTTP/1.1
Host: localhost:8080- PGFile — populates the filesystem: listens to PostgreSQL NOTIFY and writes files to disk when
db.filerecords change - db-platform
filemodule — database layer:db.filetable, UNIX-like permissions,api.get_file, REST endpoints
Follow the build and installation instructions for Apostol (C++20).
Footnotes
-
Apostol CRM — a template project built on the A-POST-OL (C++20) and PostgreSQL Framework for Backend Development frameworks. ↩