MantisDocs

Files

Folders in the schema, uploads straight to storage, and short-lived links to read them.

Files live in folders you declare in the schema, next to the tables. Each folder sets the largest file it takes, the content types it accepts and who may read, upload and delete.

mantis/schema.ts
import { defineSchema, fileRule, t, table } from "@shipmantis/sdk";

export default defineSchema(
  {
    profiles: table({ name: t.text() }),
  },
  {
    storage: {
      avatars: {
        maxBytes: 2 * 1024 * 1024,
        types: ["image/*"],
        rules: {
          read: fileRule.public(),
          insert: fileRule.signedIn(),
          delete: fileRule.uploader(),
        },
      },
    },
  },
);
database/mantis.php
<?php

return [
    'tables' => [
        'profiles' => ['columns' => ['name' => ['type' => 'text']]],
    ],
    'storage' => [
        'avatars' => [
            'maxBytes' => 2 * 1024 * 1024,
            'types' => ['image/*'],
            'rules' => [
                'read' => ['public' => true],
                'insert' => ['signedIn' => true],
                'delete' => ['owner' => true],
            ],
        ],
    ],
];

Push it with php artisan mantis:push (see Schema). Mantis::storage()->declare('avatars', 2 * 1024 * 1024) adds a folder with only its largest file, and the Files page adds one with its rules.

FieldWhat it does
maxBytesThe largest file, in bytes. Default 50 MB, at most 150 GB.
typesThe content types it accepts, like image/png or image/*. Leave it out for any type.
rulesWho may read, insert and delete. See below.

A folder's name is lowercase letters, digits, _ and -, starting with a letter. Push the schema to create it, or press New folder on the project's Files page: pick who opens the files (anyone with the link, signed-in users, or only your server) and what it holds (images up to 10 MB, videos and HLS packages up to 1 GB, or any file up to 50 MB, or a largest file of your own up to 150 GB), and it is added to main at once. Then drop files on the folder, or add the same folder to your schema file (mantis/schema.ts, or database/mantis.php from PHP) so the next push keeps it.

To change a folder's largest file later, press the pencil beside Up to … in the folder's header on the Files page, type a size up to 150 GB and save. It changes main at once; put the same maxBytes in your schema file (mantis/schema.ts, or database/mantis.php from PHP) so the next push keeps it.

const file = await mantis.storage.upload(`avatars/${userId}.webp`, blob);
// { path, size, contentType, owner, createdAt, publicUrl }

<img src={file.publicUrl} />; // a folder anyone may read
const url = await mantis.storage.url(file.path); // any folder
const files = await mantis.storage.list("avatars/"); // the first 100 by path
const { files: more, next } = await mantis.storage.listPage("avatars/", files.at(-1)?.path);
await mantis.storage.remove(file.path);
  • Paths start with the folder: avatars/me.webp. They take letters, digits, ., _ and - between single slashes, up to 512 characters.
  • upload(path, body, { contentType }) takes a Blob, an ArrayBuffer or a Uint8Array. The content type comes from the blob unless you pass one. The file goes straight to storage in 16 MB parts, four at a time, and never passes through your server. A path that already holds a file is refused: remove it first, or upload under another name.
  • publicUrl is a lasting link when the folder's read rule lets anyone in, https://cdn.shipmantis.com/{projectId}/{path}. Store it, put it in an <img> or a <video>: it never expires, and the file is cached at the edge for an hour. It is null for any other folder.
  • url(path) returns a signed link that works for five minutes. Ask for a new one each time you show the file.
  • list(prefix) returns up to 100 files whose path starts with the prefix, in path order, and only the ones the caller may read.

With the Laravel disk:

config/filesystems.php
'mantis' => ['driver' => 'mantis'],
Storage::disk('mantis')->put('avatars/me.webp', $contents);
Storage::disk('mantis')->temporaryUrl('avatars/me.webp', now()->addMinutes(5));
Storage::disk('mantis')->files('avatars');
Storage::disk('mantis')->delete('avatars/me.webp');

Or with the client, which returns the stored file:

use Shipmantis\Mantis\Laravel\Facades\Mantis;

$file = Mantis::storage()->uploadFile('avatars/me.webp', $request->file('avatar')->path());
// StoredFile { path, size, contentType, owner, createdAt, publicUrl }

$url = Mantis::storage()->url($file->path);          // a signed link for five minutes
$files = Mantis::storage()->list('avatars/');        // the first 100 by path
Mantis::storage()->delete($file->path);
  • Paths start with the folder: avatars/me.webp. They take letters, digits, ., _ and - between single slashes, up to 512 characters.
  • upload($path, $contents, $type) takes a string, uploadFile($path, $localPath) a file on disk and uploadStream($path, $stream) an open stream. upload and uploadFile guess the type from the contents unless you pass one; pass it to uploadStream. The bytes go to storage in parts, through links Mantis signs, so the bucket keys never reach your app. A path that already holds a file is refused: delete it first, or upload under another name.
  • publicUrl is a lasting link when the folder's read rule lets anyone in, https://cdn.shipmantis.com/{projectId}/{path}, cached at the edge for an hour. It is null for any other folder.
  • url($path) and the disk's temporaryUrl() return a signed link that works for five minutes, whatever expiry you ask for. Ask for a new one each time you show the file.
  • read($path), download($path, $target) and readStream($path) fetch the bytes on your server; open($path, 'bytes=0-1048575') answers a range, for a player that seeks.
  • list($prefix) returns up to 100 files whose path starts with the prefix, in path order.
  • setVisibility on the disk is refused: who reads a file is set on its folder.

Every file, page by page

list stops at 100. listPage returns the same page with a cursor; pass next back for the next one, until it is null:

let after: string | undefined;
do {
  const page = await mantis.storage.listPage("invoices/2026/", after);
  for (const file of page.files) console.log(file.path, file.size);
  after = page.next ?? undefined;
} while (after);
  • Pages are in path order, compared byte by byte: B.pdf comes before a.pdf, and 10.pdf before 9.pdf. Pad numbers (009.pdf) or use dates (2026-10-25.pdf) when the order matters.
  • The prefix is a plain prefix, not a directory: invoices/2 matches invoices/2026/a.pdf and invoices/2.pdf. End it with / for one directory.
  • A page can hold fewer than 100 files and still have a next. The files the caller may not read are dropped after the page is read, so keep going until next is null.
  • Files added during the walk appear if their path sorts after the cursor. Files removed during it don't break it.

list() stops at 100. The data api returns a cursor with each page; pass next back as after until it is null:

$after = null;
do {
    $page = Mantis::request('GET', '/v1/storage/files?'.http_build_query(array_filter([
        'prefix' => 'invoices/2026/',
        'after' => $after,
    ])));
    foreach ($page['files'] as $file) {
        echo $file['path'], ' ', $file['size'], PHP_EOL;
    }
    $after = $page['next'];
} while ($after !== null);
  • Pages are in path order, compared byte by byte: B.pdf comes before a.pdf, and 10.pdf before 9.pdf. Pad numbers (009.pdf) or use dates (2026-10-25.pdf) when the order matters.
  • The prefix is a plain prefix, not a directory: invoices/2 matches invoices/2026/a.pdf and invoices/2.pdf. End it with / for one directory.
  • Files added during the walk appear if their path sorts after the cursor. Files removed during it don't break it.

Examples

An avatar the user can change. One path per upload, so the old file stays until the new one is stored, and the browser never shows a cached old image under a new name:

components/avatar-upload.tsx (browser, publishable key)
async function changeAvatar(file: File, user: { id: string; avatar: string | null }) {
  const stored = await mantis.storage.upload(`avatars/${user.id}-${Date.now()}.webp`, file);
  await mantis.from("profiles").update({ set: { avatar: stored.path }, where: { userId: user.id } });
  if (user.avatar) await mantis.storage.remove(user.avatar);
  return stored.publicUrl;
}
avatars: {
  maxBytes: 2 * 1024 * 1024,
  types: ["image/*"],
  rules: { read: fileRule.public(), insert: fileRule.signedIn(), delete: fileRule.uploader() },
},

Private documents only their owner sees. No public link; each view asks for a five-minute one:

documents: {
  maxBytes: 25 * 1024 * 1024,
  types: ["application/pdf", "image/*"],
  rules: { read: fileRule.uploader(), insert: fileRule.signedIn(), delete: fileRule.uploader() },
},
const url = await mantis.storage.url(doc.path); // 403 for anyone but the uploader
window.open(url);

Files your server makes. An export, an invoice, a generated image: upload with the secret key into a folder with no rules, then hand out a link per download.

app/api/export/route.ts (server, secret key)
const csv = new Blob([rows.map((row) => row.join(",")).join("\n")], { type: "text/csv" });
const file = await mantis.storage.upload(`exports/${team.id}/${Date.now()}.csv`, csv);
return Response.redirect(await mantis.storage.url(file.path));

Admins moderate uploads. Anyone signed in uploads, admins remove anything:

rules: {
  insert: fileRule.signedIn(),
  read: fileRule.public(),
  delete: fileRule.any(fileRule.uploader(), fileRule.role("admin")),
},

An avatar the user can change. One path per upload, so the old file stays until the new one is stored, and no browser shows a cached old image under the new name:

app/Http/Controllers/AvatarController.php
public function update(Request $request)
{
    $request->validate(['avatar' => ['required', 'image', 'max:2048']]);
    $user = $request->user();

    $stored = Mantis::storage()->uploadFile(
        "avatars/{$user->id}-".now()->timestamp.'.webp',
        $request->file('avatar')->path(),
        $request->file('avatar')->getMimeType(),
    );
    $old = $user->avatar;
    $user->update(['avatar' => $stored->path]);
    if ($old) {
        Mantis::storage()->delete($old);
    }

    return back();
}
database/mantis.php (storage)
'avatars' => ['maxBytes' => 2 * 1024 * 1024, 'types' => ['image/*'], 'rules' => ['read' => ['public' => true]]],

Private documents only their owner sees. The folder has no rules, so only your server reaches it; your controller decides who may open a file and hands out a five-minute link:

public function show(Document $document)
{
    $this->authorize('view', $document);

    return redirect(Mantis::storage()->url($document->path));
}

Files your server makes. An export, an invoice, a generated image:

$csv = collect($rows)->map(fn ($row) => implode(',', $row))->implode("\n");
$file = Mantis::storage()->upload("exports/{$team->id}/".now()->timestamp.'.csv', $csv, 'text/csv');

return redirect(Mantis::storage()->url($file->path));

A folder made from code. declare adds a folder to main, or sets the largest file of one that is there, and returns false when nothing changed. Rules and types are set in the schema or on the Files page:

Mantis::storage()->declare('exports', 50 * 1024 * 1024);

PHP always works with the secret key, so file rules don't apply to it: your policies and gates do that job. Rules matter when a browser uploads straight to Mantis with the JavaScript SDK.

Edge cases

CaseAnswer
The path already holds a file409. Paths are never overwritten; remove it first or pick a new name.
A folder that isn't in the schema422, "there is no folder … in the schema's storage".
A path with spaces, accents, .., // or other characters422. Paths take ASCII letters, digits, ., _ and - between single slashes. A user id like Auth0's `auth0
A file larger than the folder's maxBytes422, before anything is sent.
A type the folder doesn't take422. The type comes from the blob; pass { contentType } when a Blob has none.
Larger than the plan's largest file, or the plan is full402.
The rules refuse the caller403, naming the rule.
Removing or linking a path with no file404.
Uploading or removing with a branch selected409: files belong to main.
A folder dropped from the schemaIts files stay. Only the secret key reaches them, and the Files page marks the folder as no longer in the schema.
An upload that never finishedHolds its room on the plan and doesn't appear in lists. Remove its path to free the room.
A signed link opened after five minutes403 from storage. Ask for a new one each time you show the file.
A public file replaced under the same pathNot possible, so a publicUrl always shows the same bytes; caches never serve a stale file.

Videos

Video gets its own section: HLS packages made by your ffmpeg, stored as one entry per video, played from a public link or a signed one.

  • Video overview: how it works, the ladder, sizes and costs.
  • Upload videos: the command line, the SDK, your own packages, edge cases.
  • Play videos: public and signed links, one-viewer links, a React player.
  • Recipes: a paid course, user uploads with a transcoding worker, replacing a video.

Plan limits

Uploads have their own room, apart from the data in the tables, and count every file of every project the team owns, unfinished uploads included.

PlanUploadsLargest file
Free5 GB100 MB
Pro200 GB included, then billed by the GB5 GB

An upload past the plan, or a file larger than it takes, is refused with 402. Reading and removing files go on. The plan's largest file applies whatever a folder's maxBytes allows: a folder set to 150 GB on Pro still takes files up to 5 GB.

File rules

RuleAllows
fileRule.public()Anyone with the publishable key.
fileRule.signedIn()Any signed-in user.
fileRule.uploader()The user who uploaded the file.
fileRule.role("admin")Users with that role.
fileRule.any(...), fileRule.all(...)Any one of the rules, or all of them.

An operation with no rule is refused for the publishable key; only the secret key may do it. The secret key skips the rules altogether. Rules about users need auth in the schema.

Like table rules, a file rule that lets more people in is held on main for a person's approval, and one that lets fewer in applies at once.

RuleAllows
['public' => true]Anyone with the publishable key.
['signedIn' => true]Any signed-in user.
['owner' => true]The user who uploaded the file.
['role' => 'admin']Users with that role.
['any' => [...]], ['all' => [...]]Any one of the rules, or all of them.

An operation with no rule is refused for the publishable key; only the secret key may do it. Your PHP code holds the secret key, so it skips the rules altogether: they decide what a browser using the JavaScript SDK may do. Rules about users need auth in the schema.

Like table rules, a file rule that lets more people in is held on main for a person's approval, and one that lets fewer in applies at once.

Files and branches

Files belong to the project, not to a branch. Every branch reads main's files, and uploads and removes made with a branch selected are refused, so testing on a branch can't change what users see.

On this page