Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Progress Tracking

Monitor the progress of uploads and pin operations.

UploadOperation Interface

The upload() method returns an UploadOperation with control methods:

import { Pinner } from "@lumeweb/pinner"; const pinner = new Pinner({ jwt: "YOUR_API_TOKEN" }); const operation = await pinner.upload(file); // Access the result promise const result = await operation.result; console.log("CID:", result.cid); console.log("Upload ID:", result.id); // Control the upload operation.pause(); // Pause (TUS only) operation.resume(); // Resume (TUS only) operation.cancel(); // Cancel the upload

UploadOperation Properties

PropertyTypeDescription
resultPromise<UploadResult>Promise resolving when upload completes
progressReadonly<UploadProgress>Current upload progress
cancel()() => voidCancel the ongoing upload
pause()() => voidPause the upload (TUS protocol)
resume()() => voidResume a paused upload (TUS protocol)

Progress Tracking

import { Pinner } from "@lumeweb/pinner"; const pinner = new Pinner({ jwt: "YOUR_API_TOKEN" }); const operation = await pinner.upload(file, { onProgress: (progress) => { console.log(`Progress: ${progress.percentage.toFixed(2)}%`); console.log(`Uploaded: ${progress.bytesUploaded} / ${progress.bytesTotal} bytes`); console.log(`Speed: ${progress.speed} bytes/sec`); console.log(`ETA: ${progress.eta} seconds`); } }); const result = await operation.result; console.log("Complete:", result.cid);

UploadProgress Properties

PropertyTypeDescription
percentagenumberPercentage complete (0-100)
bytesUploadednumberNumber of bytes uploaded
bytesTotalnumberTotal bytes to upload
speednumberUpload speed in bytes per second
etanumberEstimated time remaining in seconds

WaitForOperation

Wait for an operation to complete:

import { Pinner } from "@lumeweb/pinner"; const pinner = new Pinner({ jwt: "YOUR_API_TOKEN" }); const operation = await pinner.upload(file); // Get the result first const uploadResult = await operation.result; // Wait for the pinning operation to complete const result = await pinner.waitForOperation(uploadResult, { interval: 1000, // Poll every 1 second timeout: 60000 // Timeout after 60 seconds }); console.log("Status:", result); console.log("CID:", result.cid);

waitForOperation Scenarios

The waitForOperation method accepts either an operation ID (number) or an UploadResult:

Scenario 1: Wait with UploadResult (recommended)
const operation = await pinner.upload(file);
const uploadResult = await operation.result;
const result = await pinner.waitForOperation(uploadResult);
Scenario 2: Wait with operation ID from UploadResult
const operation = await pinner.upload(file);
const uploadResult = await operation.result;
const result = await pinner.waitForOperation(uploadResult.operationId);

Operation Polling Options

OptionTypeDefaultDescription
intervalnumber2000Polling interval in milliseconds
timeoutnumber300000Maximum wait time in milliseconds
settledStatesstring[]["completed", "failed", "error"]States considered settled