Build

Storage

Each database has its own file storage for images, uploads and exports, stored in the EU. Your app's server asks the Storage API for a link, and the file goes straight to or from storage with it.

The Files tab

A database's Files tab lists its files. Owners, admins and editors can add files there by hand (drop them in or choose them), download one or delete one. A deleted file can't be brought back.

The storage key

On the Files tab, choose Create storage key. Keep it on your app's server, for example as KAIVA_STORAGE_KEY, and never in a browser. It is shown once.

A new key replaces it: the current key stops working at once, so update your app with the new one. Owners, admins and editors can make a key.

Upload a file

Ask for an upload link with the file's path and its exact size in bytes, then send the file to the link with PUT and Content-Type: application/octet-stream. The link works for 15 minutes and takes exactly that many bytes.

Node.js
import fs from 'node:fs/promises';

const API = 'https://api.kaiv.ai/api/cloud/v1/storage';
const auth = { Authorization: `Bearer ${process.env.KAIVA_STORAGE_KEY}` };
const file = await fs.readFile('avatar.jpg');

// 1. Ask for an upload link for the file's exact size.
const res = await fetch(`${API}/upload`, {
  method: 'POST',
  headers: { ...auth, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    path: 'photos/ada/avatar.jpg',
    size: file.length,
  }),
});
const { url } = await res.json();

// 2. Send the file straight to storage.
await fetch(url, {
  method: 'PUT',
  headers: { 'Content-Type': 'application/octet-stream' },
  body: file,
});

Download a file

Ask for a download link with the file's path. The link works for 15 minutes, and the file is served as a download.

Node.js
const res = await fetch(`${API}/download`, {
  method: 'POST',
  headers: { ...auth, 'Content-Type': 'application/json' },
  body: JSON.stringify({ path: 'photos/ada/avatar.jpg' }),
});
const { url } = await res.json();

Every Storage API call

Each call goes to https://api.kaiv.ai/api/cloud/v1/storage with the storage key as Authorization: Bearer, and reaches only its own database's files.

CallWhat it does
POST /upload { path, size }A link to upload exactly that many bytes to the path
POST /download { path }A link to download the file
GET /files?prefix=The files under a path, up to 200, each with its path, size and last change
DELETE /files?path=Removes one file

File paths and your tables

A path such as photos/ada/avatar.jpg can't start with /, contain a . or .. part, or contain control characters.

Keep each file's path in a table next to the person it belongs to, and check that row before you ask for a download link. Keep the path, not the link: links expire, and your server can ask for a new one whenever the file is wanted.

Uploads from your website

Ask for links from your app's server. For an upload from your website, the visitor's browser sends the file to your server, which uploads it with the link. The storage key stays on the server.