Upload Files
Upload video and image files from your backend server. Files are automatically indexed for search after upload.
Basic Upload
Section titled “Basic Upload”Upload a single file by providing the file path:
import { createClient } from "zapdos-js";
const client = createClient({ apiKey: process.env.ZAPDOS_API_KEY,});
// Upload single fileconst result = await client.upload("./video.mp4");console.log("Upload completed");
Upload with Callbacks
Section titled “Upload with Callbacks”Track upload progress and indexing status:
const result = await client.upload("./video.mp4", { onProgress: ({ file_index, value }) => { console.log(`Progress: ${value}%`); }, onCompleted: ({ object_id, file_index }) => { console.log(`Upload done, object ID: ${object_id}`); }, job: { onIndexingStarted: ({ object_id, job_id }) => { console.log("Indexing started..."); }, onIndexingCompleted: ({ object_id, job_id }) => { console.log("Ready for search!"); }, },});
Upload Multiple Files
Section titled “Upload Multiple Files”Upload several files at once:
const results = await client.uploadBatch( ["./video1.mp4", "./video2.mkv", "./presentation.mp4"], { onProgress: ({ file_index, value }) => { console.log(`File ${file_index}: ${value}%`); }, onCompleted: ({ object_id, file_index }) => { console.log(`File ${file_index} uploaded: ${object_id}`); }, });
Error Handling
Section titled “Error Handling”Handle upload failures gracefully:
const result = await client.upload("./video.mp4", { onFailed: ({ message, file_index }) => { console.error(`Upload failed: ${message}`); }, job: { onIndexingFailed: ({ object_id, job_id }) => { console.error("Indexing failed, manual retry may be needed"); }, },});
All callbacks include a file_index
parameter to identify which file triggered the event when uploading multiple files.