Skip to main content
Modelence provides built-in file storage through Modelence Cloud. Files are organized by visibility — either public (accessible via a permanent URL) or private (accessible only via a time-limited signed URL).
File operations are server-only. getUploadUrl, getFileUrl, downloadFile, and deleteFile are imported from modelence/server and can only be called from your server-side code (queries, mutations, cron jobs). They are not callable directly from the browser.This is deliberate. Each operation issues a signed URL or performs a delete against Modelence Cloud using your app’s credentials, for whatever filePath it is given. The framework has no way to know which user owns which file, so exposing these to the client would let any caller act on any path. You decide who can touch which file by wrapping these calls in your own queries/mutations and enforcing ownership there — see Exposing file operations to the client.

Uploading a File

getUploadUrl returns a presigned URL and form fields. POST these together as FormData to upload the file directly to storage:
The visibility field controls access:
  • "public" — the file is accessible via a permanent URL
  • "private" — the file requires a signed URL to access

Getting a File URL

Returns a URL for displaying or linking to a file. For public files this is a permanent URL; for private files it is a time-limited presigned URL.

Downloading a File

Returns a presigned download URL for a private file.

Deleting a File

File Paths

File paths always include the visibility prefix: public/<path> or private/<path>. The upload functions return the full filePath (including prefix) in their result, which you can store and pass to the other functions.

Exposing file operations to the client

Because the file functions are server-only, the browser reaches them through your own queries and mutations. This is where you enforce authorization: never accept a raw client-supplied filePath and forward it blindly — derive the path from your own data and verify the current user is allowed to act on it. The pattern below stores file ownership in a Store and checks it on every operation. Uploading returns the presigned URL to the client, which performs the actual upload directly to storage.
The client then calls your guarded methods — e.g. callMethod('documents.requestUpload', { contentType }) — instead of the file functions directly. Public assets that are safe for anyone to read can be served straight from their permanent public/... URL without a query.