Your app
Your users upload
Files go from your code straight to storage in parts, side by side, or Crumbcast fetches them from a link.
- Straight to storageEach part goes to a signed URL of your storage, never through the API.
- In parts, side by sideSend parts at once, and try a failed one again on its own.
- Or from a linkName a file that's online, and Crumbcast downloads it for you.
import { Crumbcast } from "crumbcast"; const crumbcast = new Crumbcast({ token: process.env.CRUMBCAST_TOKEN, baseUrl: "https://your-crumbcast",}); // file: a browser File, or fs.openAsBlob(path) in Node// In parts, straight to storage; then encoding startsconst video = await crumbcast.uploadVideo(projectId, file, { title: "Launch day",}, { onProgress: (part) => show(part.uploaded / part.total),}); // Or have Crumbcast fetch it from a linkawait crumbcast.videos.importVideo({ project_id: projectId, importVideoRequest: { url: "https://example.com/launch.mp4", title: "Launch day", },});import os from crumbcast import Crumbcast crumbcast = Crumbcast( token=os.environ["CRUMBCAST_TOKEN"], base_url="https://your-crumbcast",) # file: a path, an open file, or its bytes# In parts, straight to storage; then encoding startsvideo = crumbcast.upload_video( project_id, "launch.mp4", {"title": "Launch day"}, on_progress=lambda part: show(part.uploaded / part.total),) # Or have Crumbcast fetch it from a linkcrumbcast.videos.import_video( project_id, body={ "url": "https://example.com/launch.mp4", "title": "Launch day", },)use Crumbcast\Crumbcast; $crumbcast = new Crumbcast( token: getenv('CRUMBCAST_TOKEN'), baseUrl: 'https://your-crumbcast',); // $file: a path, an SplFileInfo, or an open stream// In parts, straight to storage; then encoding starts$video = $crumbcast->uploadVideo( $projectId, 'launch.mp4', ['title' => 'Launch day'], onProgress: fn ($part) => show($part->uploaded / $part->total),); // Or have Crumbcast fetch it from a link$crumbcast->videos->importVideo($projectId, [ 'url' => 'https://example.com/launch.mp4', 'title' => 'Launch day',]);const api = "https://your-crumbcast/api/v1";const headers = { Authorization: `Bearer ${process.env.CRUMBCAST_TOKEN}`, "Content-Type": "application/json",}; // file: a Blob, e.g. await fs.openAsBlob("launch.mp4")const post = (path, body) => fetch(`${api}${path}`, { method: "POST", headers, body: JSON.stringify(body) }) .then((response) => response.json()); // 1. Say what the file is, and hear how to cut itconst { video, upload } = await post(`/projects/${projectId}/videos/`, { title: "Launch day", name: "launch.mp4", size: file.size,}); // 2. Each part straight to storage, up to 100 URLs at a timeconst numbers = Array.from({ length: upload.part_count }, (_, i) => i + 1);for (let at = 0; at < numbers.length; at += 100) { const part_numbers = numbers.slice(at, at + 100); const { urls } = await post(`/videos/${video.id}/upload/parts/`, { part_numbers }); await Promise.all(urls.map(({ part_number, url }) => { const start = (part_number - 1) * upload.part_size; return fetch(url, { method: "PUT", body: file.slice(start, start + upload.part_size) }); }));} // 3. Every part is in: encoding startsawait post(`/videos/${video.id}/uploaded/`);