Unify Logo Footer.svg
Unify Applications
Logo
Control Media Uploads

Control Media Uploads

Logo

3 mins READ

Overview

The controlMediaUploads action gives you direct control over the upload lifecycle managed by a File Upload or Camera block. By default, these blocks begin uploading as soon as the user selects files. This action lets you override that behaviour — holding files in a queue until the user explicitly clicks "Upload All", retrying failed uploads, or cancelling uploads that are no longer needed.

The action returns a queue status snapshot that you can use to update a progress indicator or enable/disable related buttons.

Parameters

ParameterTypeRequiredDefaultDescription
blockRefstringRequired (required)Block ID of the File Upload or Camera block whose upload queue to control. The block must have Auto Upload disabled in its settings for pause/resume to have any effect. If the block doesn't exist, the action is a silent no-op.
operation"start" | "pause" | "resume" | "cancel" | "clearQueue"Required (required)start — begins uploading all pending files in the queue. pause — suspends the current upload mid-stream (if the server supports range requests) or after the current file completes. resume — resumes a paused upload from where it stopped. cancel — aborts all active uploads; files matching filter are removed from the queue. clearQueue — removes files from the queue without cancelling active uploads. Combine with filter: "failed" to remove only errored files.
filter"all" | "pending" | "failed"Optional (optional)"all"Scopes the operation to a subset of the queue. pending targets files waiting to upload. failed targets files in an error state. all targets every file in the queue. Ignored by start and resume.

Return Value — Upload Queue Status

The action resolves with a queueStatus object. Store it in a page variable to drive progress indicators:

FieldTypeDescription
totalFilesnumberTotal files in the queue (all states).
pendingCountnumberFiles waiting to start.
uploadingCountnumberFiles currently transferring.
completedCountnumberSuccessfully uploaded files.
failedCountnumberFiles that encountered an error.
totalBytesnumberCombined size of all files in bytes.
uploadedBytesnumberBytes transferred so far across all files.
progressPercentnumberOverall progress 0–100.

Step-by-Step Usage Guide

  1. Disable auto-upload on the File Upload block: Select the File Upload block, open Settings → Upload Behaviour, and turn off Auto Upload on Select. Files will now queue without transferring.

  2. Add Upload All and Retry Failed buttons: Add two buttons to the page: "Upload All" and "Retry Failed". Bind "Upload All" to a start operation; bind "Retry Failed" to a start operation scoped with filter: "failed" on a re-queue action, then start again. Conditionally hide "Retry Failed" when {{ b_fileUpload.state.failedCount === 0 }}.

  3. Show a progress bar: Bind a Progress Bar block's value to {{ b_fileUpload.state.uploadProgress }} (the block's built-in progress variable). Alternatively, store the return value of controlMediaUploads and read queueStatus.progressPercent.

  4. Handle completion: Listen to the File Upload block's onAllUploadsComplete event to fire subsequent actions — saving a record, showing a success notification, or navigating away.

Examples

Start uploading all pending files

{ "actionType": "controlMediaUploads", "payload": { "blockRef": "b_documentUploader", "operation": "start", "filter": "pending" } }

Retry only failed uploads

// Step 1: Clear failed items from queue to reset their state { "actionType": "controlMediaUploads", "payload": { "blockRef": "b_documentUploader", "operation": "clearQueue", "filter": "failed" } } // Step 2: Re-add and start (user re-selects files, or use a stored file list) { "actionType": "controlMediaUploads", "payload": { "blockRef": "b_documentUploader", "operation": "start" } }

Cancel all active uploads and clear the queue

{ "actionType": "controlMediaUploads", "payload": { "blockRef": "b_documentUploader", "operation": "cancel", "filter": "all" } }

Warning: Pause support depends on the upload endpoint. The pause operation sends an HTTP request abort signal to the in-progress upload. Whether the server supports resuming from a byte offset depends on your storage backend (S3 multipart, TUS protocol, etc.). Without server-side support, resume will re-upload the entire file from the beginning.