SkybuDocs

Ferdigheter · Filer

Store files

Store an app's uploads and generated files in the project's S3 bucket, and let browsers upload and download them with presigned URLs.

skill://files/store-filesAgenter leser den med resources/read eller skills_read. Den er skrevet på engelsk, for agentene.

Every project has its own private S3 bucket (Garage). The project's apps get its address and an access key as SKYBU_S3_* variables, so code that uses an S3 SDK works without any setup. The key can read and write that one bucket and nothing else.

In short

  1. get_file_storage to see the bucket, its status and how much of the organisation's quota is used.
  2. In the app, make an S3 client from the SKYBU_S3_* variables, with path-style addressing.
  3. Read and write from the server against SKYBU_S3_ENDPOINT.
  4. For browser uploads and downloads, sign URLs against SKYBU_S3_PUBLIC_URL and hand them to the browser.

Step 1: the bucket

{ "name": "get_file_storage", "arguments": { "projectId": "<project id>" } }

You get bucket (files-p-…), status (provisioning, ready or suspended), endpoint, publicUrl, region, objects, and usage with usedBytes and maxBytes. The quota belongs to the organisation and is shared by all its projects (10 GiB unless Skybu has set another).

Step 2: the variables apps get

VariableValue
SKYBU_S3_ENDPOINTThe address inside the platform, for the app's own requests
SKYBU_S3_PUBLIC_URLhttps://files.skybu.app, for URLs a browser uses
SKYBU_S3_BUCKETThe project's bucket
SKYBU_S3_REGIONoslo
SKYBU_S3_ACCESS_KEY_IDThe project's access key
SKYBU_S3_SECRET_ACCESS_KEYIts secret

All apps in the project share the bucket, so give each app its own key prefix (invoices/, avatars/). The standard AWS_* variables are not set; pass these to the SDK yourself. Previews get no SKYBU_S3_*: pull request code does not touch production files. SKYBU_* names are reserved and cannot be set with set_env_vars.

Step 3: code (AWS SDK v3 for Node)

Install @aws-sdk/client-s3 and @aws-sdk/s3-request-presigner. Use two clients: one for the app's own requests, one for signing URLs that browsers use. A presigned URL is only valid for the host it was signed for.

import { S3Client, PutObjectCommand, GetObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";

const env = process.env;
const options = {
  region: env.SKYBU_S3_REGION,
  credentials: { accessKeyId: env.SKYBU_S3_ACCESS_KEY_ID, secretAccessKey: env.SKYBU_S3_SECRET_ACCESS_KEY },
  forcePathStyle: true,
};
const s3 = new S3Client({ ...options, endpoint: env.SKYBU_S3_ENDPOINT });
const browserS3 = new S3Client({ ...options, endpoint: env.SKYBU_S3_PUBLIC_URL });
const Bucket = env.SKYBU_S3_BUCKET;

export async function saveReport(key, body) {
  await s3.send(new PutObjectCommand({ Bucket, Key: `reports/${key}`, Body: body, ContentType: "application/pdf" }));
}

export function uploadUrl(key, contentType) {
  return getSignedUrl(browserS3, new PutObjectCommand({ Bucket, Key: `uploads/${key}`, ContentType: contentType }), { expiresIn: 600 });
}

export function downloadUrl(key) {
  return getSignedUrl(browserS3, new GetObjectCommand({ Bucket, Key: key }), { expiresIn: 300 });
}

The browser then sends the file straight to Skybu, not through the app:

const { url } = await (await fetch(`/api/upload-url?type=${encodeURIComponent(file.type)}`)).json();
await fetch(url, { method: "PUT", body: file, headers: { "Content-Type": file.type } });

Decide in the app who may upload and download what before signing; the URL is the permission. Keep the expiry short. Multipart uploads from the browser work too: CORS exposes ETag, so the browser can collect each part's ETag.

Credentials and rotation

{ "name": "get_file_storage_credentials", "arguments": { "projectId": "<project id>" } }

Returns the access key and the full SKYBU_S3_* set, for a script or a tool outside Skybu. It needs secrets:read, is written to the audit log, and the organisation's owners get an email when an agent reads it. Do not put the key in code, a repository or chat; apps already have it.

{ "name": "rotate_file_storage_key", "arguments": { "projectId": "<project id>" } }

A new key: the old one stops working at once, presigned URLs signed with it included, and the apps restart with the new one. Use it when the key may have leaked.

Things to know

  • No public buckets. Every request needs a signature; a plain link to an object gets 403. To show images on a public page, serve them through the app or hand out presigned GET URLs.
  • No custom CORS rules. Every bucket has one rule set by Skybu: any origin, GET, HEAD, PUT, POST, DELETE. That is safe because the signature, not CORS, grants access.
  • No versioning or object lock. An overwritten or deleted object is gone. Do not overwrite keys you may need back; write new ones.
  • The key cannot change the bucket. It has no owner permission: no bucket policies, lifecycle rules or deleting the bucket.
  • Quota. A write that would take the organisation over its file quota is refused with AccessDenied: Bucket size quota is reached. Check usage with get_file_storage; only Skybu staff can raise the quota, so the user must ask.
  • Suspension denies the key its bucket, presigned URLs included, until the organisation is reinstated.
  • Deleting a project empties and deletes its bucket.
  • From the CLI: skybu files info <project>, skybu files credentials <project>, skybu files rotate <project>.
  • Moving files from Supabase Storage: skybu supabase import --project <name> --storage (skill://playbooks/leave-supabase).