Advanced Manual Usage
For production workflows, you may want to split the upload phase from the download/polling phase. Decoupling these steps is highly recommended if:
- You are running a distributed application where a frontend client uploads a file, and a separate background service processes or downloads it.
- You want to store the
capture_idin your local database immediately for auditing before starting the polling cycle. - You need to handle server errors or network disconnects gracefully during the polling period.
Decoupled Upload & Poll Lifecycle
// Step 1: Upload the raw capture. Returns metadata immediately.
using var sourceStream = File.OpenRead("photo.jpg");
var capture = await client.UploadAsync(
filter: "claymation-001",
stream: sourceStream,
width: 1024,
height: 1024
);
var captureId = capture.Id.Value.ToString();
Console.WriteLine($"Upload complete! Capture ID: {captureId}");
// Step 2: Perform other application tasks, store ID in database, etc.
await SaveToDatabaseAsync(captureId);
// Step 3: Trigger download/polling later (polls until complete, then returns stream)
using var processedStream = await client.DownloadAsync(captureId);
if (processedStream != null)
{
using var dest = File.Create("output.jpg");
await processedStream.CopyToAsync(dest);
}