File uploads for deployed apps use presigned upload URLs to Gipity Storage. The client uploads directly to storage (no server proxy), supporting files up to 30GB with progress tracking.

This skill covers getting files in. Two companions cover the rest:

How It Works

  1. Init - App calls POST /api/<APP_GUID>/uploads/init with file metadata. Server returns a presigned upload URL.
  2. Upload - Client PUTs the file directly to the presigned URL. No auth header needed - the URL is pre-authorized.
  3. Complete - App calls POST /api/<APP_GUID>/uploads/complete. Server copies the file to permanent Gipity Storage, records it, and generates variants (thumbnails for images, text for PDFs, ID3 tags + cover-art thumbnail for audio). For audio it also returns the parsed tags on data.audio.

Uploads are runtime content, not source. A file stored through this API (by your app's users, by gipity upload, or by an external service calling it with a project API key) lands at <path>/<guid>/<filename> in Gipity Storage, whatever path you pick, and stays there: gipity sync and the editor hooks never pull it into your working directory (so it can't end up in git), never push a local copy back, never delete it, and gipity deploy never ships it even under src/. Serve it by its url; see it with gipity file tree, gipity file cat <path> or Monitor's Files tab. A sandbox run (gipity sandbox run) still sees it under /work/.

Client Helper Library

The client SDK (gipity.js, auto-injected into every template via {{ANALYTICS_SCRIPT}}) exposes Gipity.upload for automatic progress tracking, multipart handling, and retries. No extra script tag is needed.

const result = await Gipity.upload(fileInput.files[0], {
  onProgress: (pct) => progressBar.style.width = pct + '%',
  public: false,
  table: 'attachments',
  recordId: 'rec_123',
});
console.log(result.guid, result.url);

The SDK auto-supplies appGuid (the script tag's data-app) and the app's public appToken. Pass { appGuid, appToken } only from a page that doesn't load the SDK with data-app.

Single-part (< 5GB) and multipart (5GB+) uploads are handled transparently. Each multipart part gets up to 3 attempts with exponential backoff.

Verifying the upload flow end-to-end from the CLI. To drive this signed-in path against a real file - upload a PDF, then assert whatever ingest/extract runs next - use gipity page eval --auth --fixture ./sample.pdf. --fixture hosts the local file ephemerally, injects a fetch-able fixtureUrl into the eval, and deletes the hosted copy afterwards - so you never bundle a test file into src/ or run an extra deploy just to make it reachable. Fetch it in-page, wrap the bytes in a File, and hand it to Gipity.upload:

gipity page eval "https://dev.gipity.ai/me/app/" --auth --fixture ./sample.pdf \
  "(async()=>{ const b = await fetch(fixtureUrl).then(r=>r.blob()); const f = new File([b], 'sample.pdf', { type: 'application/pdf' }); const { guid } = await Gipity.upload(f); return { guid }; })()"

Repeat --fixture for several files (each also exposed under fixtures['<basename>']). Full reference: app-debugging-reference.

Just need a durable URL for a local file? gipity upload <file> uploads it into this same store and prints a worker-reachable URL immediately (no deploy) - public CDN by default, --private for a token-signed serve url. Handy for feeding a job or function a real input; see jobs.

Folder & multi-file uploads

Gipity.upload takes one File. For a folder drop or a multi-file picker, the browser makes you do fiddly, easy-to-get-wrong traversal first: a dropped folder leaves dataTransfer.files empty (or a zero-byte stub), so you must read the non-standard entry tree - capturing webkitGetAsEntry() synchronously in the drop handler (the items list goes stale the instant it returns) and looping readEntries(), which pages at 100 entries per call. The SDK owns that for you.

Gipity.collectFiles(source) normalizes a drop event, a DataTransfer, an <input webkitdirectory>, a plain <input multiple>, a FileList, or a File[] into a flat list. Each entry is { file, relativePath }, where relativePath is the path within the drop ("Album/Disc 1/track01.mp3") - just the filename for a loose file. It's traversal only: loop and call Gipity.upload yourself, or hand the list to uploadAll.

// In the drop handler - call collectFiles SYNCHRONOUSLY (don't await anything first).
dropZone.addEventListener('drop', async (e) => {
  e.preventDefault();
  const items = await Gipity.collectFiles(e);          // [{ file, relativePath }, ...]
  for (const { file, relativePath } of items) {
    await Gipity.upload(file, { path: relativePath.split('/').slice(0, -1).join('/') });
  }
});

// Or from a folder picker:
//   <input type="file" webkitdirectory multiple>
input.addEventListener('change', () => Gipity.collectFiles(input).then(...));

Gipity.uploadAll(items, opts?) uploads a whole batch and mirrors the folder structure for you - each file's relativePath directory is appended to opts.path, so the tree lands the same way in storage. It accepts the array from collectFiles, or a raw drop/input it collects for you. Uploads run opts.concurrency at a time (default 3) and one file failing does not abort the batch - you get a per-item report. Pass { stopOnError: true } to reject on the first failure instead.

const report = await Gipity.uploadAll(e, {       // pass the drop event directly
  path: 'locker',                                // base path; folders nest under it
  concurrency: 4,
  onProgress: (overall, info) => bar.style.width = overall + '%',  // 0-100 across the whole batch
});
// report.succeeded, report.failed, report.results: [{ relativePath, file, ok, value?, error? }, ...]
const failures = report.results.filter((r) => !r.ok);

opts also forwards appGuid, appToken, apiKey, public, table, recordId, and signal to each Gipity.upload call.

Client SDK surface

Browser globals from gipity.js: Gipity.upload, Gipity.collectFiles, Gipity.uploadAll, Gipity.fileUrl, Gipity.fn, Gipity.auth, Gipity.captureError, Gipity.version. upload stores one file; collectFiles flattens a folder drop / directory picker into { file, relativePath }[]; uploadAll uploads such a batch (mirroring folders under a base path); fileUrl gets an embeddable URL to display one (see app-files-display). To delete files, call your own functions via Gipity.fn (see app-files-storage). Anonymous visitors CAN upload (the SDK uses the app's public token), so gate the UI on Gipity.auth if uploads must be signed in.

Endpoints

POST /api//uploads/init

Get a presigned upload URL.

Auth: App token (X-App-Token; the session cookie rides along with it), Authorization: Bearer, or API key (X-Api-Key).

Request:

{
  "filename": "photo.jpg",
  "content_type": "image/jpeg",
  "size": 2048576,
  "public": false,
  "table": "incidents",
  "record_id": "42",
  "path": "uploads"
}

Response (single-part, < 5GB):

{
  "data": {
    "upload_guid": "fl_Xk7mNp2R",
    "method": "PUT",
    "url": "https://muda.gipity.ai.s3...",
    "headers": { "Content-Type": "image/jpeg" },
    "expires_in": 600
  }
}

Response (multipart, >= 5GB):

{
  "data": {
    "upload_guid": "fl_Xk7mNp2R",
    "method": "multipart",
    "upload_id": "abc123...",
    "part_size": 104857600,
    "parts": [
      { "partNumber": 1, "url": "https://..." },
      { "partNumber": 2, "url": "https://..." }
    ],
    "expires_in": 600
  }
}

PUT each part_size slice of the file to its part's URL (the last part is whatever remains) and keep the ETag response header of each PUT for complete.

POST /api//uploads/complete

Finalize the upload after the client has PUT the file to storage.

Request:

{
  "upload_guid": "fl_Xk7mNp2R",
  "parts": [
    { "part_number": 1, "etag": "\"abc123\"" },
    { "part_number": 2, "etag": "\"def456\"" }
  ]
}

Response:

{
  "data": {
    "guid": "fl_Xk7mNp2R",
    "name": "photo.jpg",
    "size": 2048576,
    "content_type": "image/jpeg",
    "width": 1920,
    "height": 1080,
    "audio": null,
    "url": "https://media.gipity.ai/app-files/...",
    "is_public": false,
    "table": "incidents",
    "record_id": "42",
    "variants": [
      { "type": "thumbnail", "url": "...", "content_type": "image/jpeg", "size_bytes": 8421, "width": 200, "height": 200, "status": "complete" }
    ]
  }
}

width/height are set for images, audio carries parsed tags for audio files, and warnings (when present) says why a variant was skipped. What each field means for display: app-files-display.

GET /api//files

List the app's runtime uploads (never source files). Visitors see public uploads plus their own private ones (signed in, or app players); the owner, members and API keys see all.

Query params: table, record_id, path, limit (default 50, max 200), offset

GET /api//files/:guid

Get file metadata + variant list.

Who can read a private file (is_public: false) here, on /content and on /variants/:type: its uploader, the app owner, project members, and this project's API keys (a scoped key needs --files read). A Gipity account reaching these routes by its session cookie (the X-App-Token flow) counts as the uploader or a member only after it signed in to this app (Gipity.auth.signIn(), identity consent), the same rule functions apply; the owner always counts. Until then the call is anonymous: it lists and reads public files only, and its uploads aren't attributed to anyone. Everyone else, including anonymous visitors holding the guid, gets 404, the same as a missing file. A guid is not a secret. To let anyone else view a private file, hand them its durable serve URL (Gipity.fileUrl resolved by the uploader or an admin, or storage.fileUrl from a function); revoke it with storage.revokeFileUrl.

GET /api//files/:guid/content

Download file (auth-gated); 302s to storage. Convenience endpoint; for an embeddable/persistable URL use the durable serve URL below.

GET /api//files/:guid/serve?t=

The durable, embeddable access URL for a private file. Auth is a capability token in ?t=, not a header, so it works in <img>, <audio>, <a download> and for signed-out viewers, and it never expires on its own. You don't build it by hand: Gipity.fileUrl (client) and storage.fileUrl (functions) return it. Details: app-files-display.

GET /api//files/:guid/variants/:type

Get a specific variant (e.g., thumbnail), auth-gated. Redirects to storage.

Limits

Manual Upload (without helper library)

If you can't use the helper library (a page that doesn't load gipity.js, or a script with a project API key), implement the three-step flow directly. Single-part shown; for files of 5GB and up, init returns method: "multipart" and you PUT each part, then send the parts ETags to complete (see Endpoints).

// 1. Init
const init = await fetch(`https://a.gipity.ai/api/${appGuid}/uploads/init`, {
  method: 'POST',
  headers: { 'X-App-Token': token, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    filename: file.name,
    content_type: file.type,
    size: file.size,
  }),
}).then(r => r.json());

// 2. Upload to storage
await fetch(init.data.url, {
  method: 'PUT',
  headers: { 'Content-Type': file.type },
  body: file,
});

// 3. Complete
const result = await fetch(`https://a.gipity.ai/api/${appGuid}/uploads/complete`, {
  method: 'POST',
  headers: { 'X-App-Token': token, 'Content-Type': 'application/json' },
  body: JSON.stringify({ upload_guid: init.data.upload_guid }),
}).then(r => r.json());

console.log(result.data.url); // permanent file URL

From a script or server, send X-Api-Key: <project API key> instead of X-App-Token (see app-api-keys).

Integration with Records

Files can be associated with records via table and record_id fields (soft reference). Example flow:

  1. User uploads a screenshot with table: 'incidents', record_id: '42'
  2. Frontend lists attachments via GET /api/:app/files?table=incidents&record_id=42 (visitors see public ones plus their own; for others to see a private attachment, store its serve URL from storage.fileUrl on the record)
  3. Each attachment shows the thumbnail variant as a preview (see app-files-display)

To attach an upload to a record from a function, check the caller uploaded it first: app-files-storage.

Related Skills