remagicaDocs home

Uploading files

Put your images, videos and audio in storage, then pass them to the API by key.

The API never takes file bytes in a JSON body. You upload a file to storage first, then pass its storage key to whatever needs it: a generation's references, a video's first frame, a clip job's source, an app's media input.

Uploading needs uploads:write.

Upload a file

  1. Ask for an upload URL with the file's name, MIME type and size:

    curl https://api.remagica.com/api/v1/uploads \
      -H "x-api-key: $REMAGICA_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{ "filename": "keynote.mp4", "contentType": "video/mp4", "size": 734003200 }'

    The response has a presigned uploadUrl, the headers to send with it, when it expires (expiresAt, 15 minutes) and the file's storage key.

  2. PUT the raw bytes to uploadUrl, with exactly the returned headers. The bytes go straight to storage, not through the API.

    curl -X PUT "$UPLOAD_URL" \
      -H "Content-Type: video/mp4" \
      --data-binary @keynote.mp4
  3. Use the key once the PUT has finished.

In JavaScript:

import { readFile, stat } from "node:fs/promises";

async function upload(path: string, contentType: string): Promise<string> {
  const { size } = await stat(path);
  const ticket = await fetch("https://api.remagica.com/api/v1/uploads", {
    body: JSON.stringify({
      contentType,
      filename: path.split("/").pop(),
      size,
    }),
    headers: {
      "Content-Type": "application/json",
      "x-api-key": process.env.REMAGICA_API_KEY,
    },
    method: "POST",
  }).then((response) => response.json());

  const put = await fetch(ticket.uploadUrl, {
    body: await readFile(path),
    headers: ticket.headers,
    method: "PUT",
  });
  if (!put.ok) {
    throw new Error(`Upload failed: ${put.status}`);
  }
  return ticket.key;
}

If an image, video or audio file is already online, POST /uploads/from-url with its url copies it into your storage (up to 200 MB) and returns its key, kind and contentType. Links to private addresses are refused.

Signed URLs for your files

POST /files/urls with a list of keys returns files: a short-lived download URL for each key, by key. Keys that aren't your workspace's files are left out.

Limits

  • One file can be up to 5 GiB minus 5 MiB (5,363,466,240 bytes).
  • Accepted types are any video/*, audio/* or image/*, plus PDF and Word (.docx) files for brand kits.
  • Upload URLs expire after 15 minutes. Ask for a new one if yours runs out.

On this page