Skip to main content

useUploadQueue

Manages a queue of files being uploaded, choosing base64 or a chunked provider per file.

It is what UploadInput runs on. Use it directly only when you build your own upload UI and still want chunked uploads, retries and progress.

The hook is free. It resolves the chunked path through the core's transport registry, which habarico-enterprise fills — or which you can fill yourself, see File uploads.

Signature​

import {useUploadQueue, type BuildFileModifier} from 'habarico';

const {entries, addAndUpload, removeEntry, removeAll, retryUpload, updateEntry, getUploadErrorMsg} =
useUploadQueue({
upload, // UploadTransportConfig | undefined — undefined means base64 only
maxFileSize, // number | undefined
showPreview, // boolean — default true
fileModifier, // BuildFileModifier | undefined
initialEntries, // UploadEntry[]
onUploadSuccess, // (id, uploadData) => void
});

Parameters​

NameTypeDefaultDescription
uploadUploadTransportConfig—Chunked-upload config; without it every file goes the base64 route. Structurally identical to the schema's UploadFieldOptions, so field.options.upload can be passed straight in
maxFileSizenumber—Files above this size are rejected before anything is sent
showPreviewbooleantrueStores a preview URL on the entry
fileModifierBuildFileModifier—Factory returning a transform applied to the data URL (resize, crop)
initialEntriesUploadEntry[][]Pre-existing files, e.g. what the record already has
onUploadSuccess(id, uploadData) => void—Called per finished file

Returns​

NameTypeDescription
entriesUploadEntry[]The queue, in insertion order
addAndUpload(files: File[]) => voidAdds files and starts uploading immediately
removeEntry(id: string) => voidAborts the upload if running, then drops the entry
removeAll() => voidAborts everything and clears the queue
retryUpload(id: string) => voidRetries one failed entry
updateEntry(id: string, patch: UploadEntryPatch) => voidAdvanced: patches progress, error, previewUrl, filename, uploaded, uploadResult, isChunkedUpload or done
getUploadErrorMsg(e: unknown) => stringTranslated message for a caught upload error

UploadEntry​

FieldTypeDescription
idstringQueue identifier
fileFile | undefinedAbsent for entries loaded from the backend
filenamestringFile name
fileSizenumber | undefinedAbsent for entries loaded from the backend
progressnumber | null0–100 during a chunked upload, null otherwise
isChunkedUploadbooleanWhether this file took the chunked path
errorstring | nullFailure message
uploadedboolean | undefinedtrue once the file reached storage — drives the "Complete" indicator
previewUrlstring | undefinedSet for base64 uploads only — a chunked upload has no viewable URL until the record is saved
uploadResultobject | undefined{upload_key} for chunked, {filename, content} for base64
donebooleanUpload finished successfully

Behaviour​

  • A file reaching upload.threshold takes the chunked path when upload is set; smaller files are base64-encoded. With no chunked transport registered, that file fails with an explanatory error instead of falling back to base64.
  • fileModifier runs on the base64 path only — a chunked upload sends the raw file.
  • Uploads in flight are aborted when the component unmounts.
  • tus uploads retry with back-off; s3-multipart does not resume across a page reload.

See also​