Skip to navigation

Extension Points

The registry API is the main extension point. Call its methods from inside setup to add capabilities to the uploader.

Labels

A source, activity or file action label is an l10n key or text that is shown as written. The PlainText and CustomLocaleDefinition types used below are available Since v1.37.0.

  • An l10n key is looked up in the current locale. A built-in key works as is, and so does a key that any plugin registers with registerL10n. Declare your own keys by augmenting CustomLocaleDefinition so that your editor suggests them.
  • Text that is not a key is shown as written. In TypeScript, assert it as PlainText ('Edit' as PlainText) to say it is meant as text rather than a key. It is still looked up in the locale like any label, so text that happens to equal a key shows that key’s translation.
import type { PlainText } from '@uploadcare/file-uploader';
declare module '@uploadcare/file-uploader' {
interface CustomLocaleDefinition {
'my-source.label': string;
}
}
pluginApi.registry.registerSource({ id: 'a', label: 'src-type-local', onSelect }); // built-in key
pluginApi.registry.registerSource({ id: 'b', label: 'my-source.label', onSelect }); // declared key
pluginApi.registry.registerSource({ id: 'c', label: 'My source' as PlainText, onSelect }); // plain text

Any string still compiles in TypeScript, so a misspelled key compiles too and is shown as written. Declaring your keys in CustomLocaleDefinition and asserting text as PlainText keeps the two apart; a future major version will accept only those.

registerSource

Adds an entry to the source picker (the list of upload origins users can choose from).

pluginApi.registry.registerSource({
id: 'my-source',
label: 'my-source.label', // an l10n key, or 'My source' as PlainText
icon: 'my-icon', // name of a registered icon
onSelect() {
uploaderApi.navigate('my-activity');
},
});
PropertyTypeRequiredDescription
idstringYesUnique source identifier. Referenced in the sourceList config.
labelstringYesAn l10n key or text; see Labels.
iconstringNoName of a registered icon (see registerIcon).
onSelect() => void | Promise<void>YesCalled when the user picks this source. Use navigate() to show your own activity or a built-in one, such as 'url'.

registerActivity

Registers a custom UI panel rendered inside the uploader. Activities are identified by id and rendered on demand via uploaderApi.navigate().

pluginApi.registry.registerActivity({
id: 'my-activity',
render(host, params) {
const el = document.createElement('my-activity-element');
host.append(el);
// return a dispose function
return () => {
host.replaceChildren();
};
},
});

The render function receives:

ArgumentTypeDescription
hostHTMLElementContainer element managed by the uploader. Append your UI here.
paramsRecord<string, unknown>The params passed to navigate() when the activity was opened.

Return a cleanup function (or nothing) from render. It is called when the activity unmounts.

Naming the activity’s dialog

Since v1.37.0 When your activity opens in a modal, its dialog is announced to screen readers by the label you register with it. Without a label the dialog has no accessible name.

pluginApi.registry.registerActivity({
id: 'my-activity',
label: 'my-plugin.title', // an l10n key, or 'My panel' as PlainText; see Labels
render(host) {
/* ... */
},
});

label can also be a function of the activity’s params, for an activity whose name depends on how it was opened. While the activity is closed, it gets {}. It returns a label, or undefined for none. If you declared the activity’s params in CustomActivities (see below), the function receives them typed, each one optional:

// With CustomActivities { 'my-activity': { params: { folder: string } } }
pluginApi.registry.registerActivity({
id: 'my-activity',
label: (params) => (params.folder ? `Files in ${params.folder}` : 'Files') as PlainText,
render(host) {
/* ... */
},
});

Tip: The render function receives a plain HTMLElement host, so you can use any library or framework to render your activity UI — React, Vue, Svelte, or vanilla DOM. Just mount into host and unmount in the returned cleanup function.

TypeScript: declaring a custom activity

Augment the CustomActivities interface so navigate() is typed:

declare module '@uploadcare/file-uploader' {
interface CustomActivities {
'my-activity': { params: { fileId?: string } };
}
}

Use never for the params type if your activity takes no parameters. When every param is optional, as here, navigate('my-activity') without params compiles too.


registerFileAction

Adds a per-file action button to the file list (e.g. “Edit image”).

pluginApi.registry.registerFileAction({
id: 'my-action',
icon: 'my-action-icon',
label: 'Edit' as PlainText,
shouldRender(fileEntry) {
return fileEntry.isSuccess && fileEntry.isImage;
},
onClick(fileEntry) {
uploaderApi.navigate('my-activity', { fileId: fileEntry.internalId });
},
});
PropertyTypeRequiredDescription
idstringYesUnique action identifier.
iconstringYesName of a registered icon.
labelstringYesAn l10n key or text; see Labels.
shouldRender(fileEntry: OutputFileEntry) => booleanYesReturn true to show the action for a given file.
onClick(fileEntry: OutputFileEntry) => void | Promise<void>YesCalled when the user clicks the action.

OutputFileEntry is described in the API reference.

File actions from plugins appear to the left of the built-in remove button, in the order their plugins were registered.


registerFileHook

Intercepts files at defined lifecycle points so you can transform them before the uploader continues processing.

pluginApi.registry.registerFileHook({
type: 'beforeUpload',
async handler({ file, signal }) {
const processed = await processFile(file, { signal });
return { file: processed };
},
});
PropertyType / ValueDescription
type'beforeUpload' | 'onAdd'When to run the hook. See below.
handler(ctx) => result | Promise<result>Receives { file, signal } and must return { file }. Return the original file unchanged if no transformation is needed.
timeoutnumberMaximum milliseconds to wait for the handler before skipping it. Default: 30000.

The handler context contains:

PropertyTypeDescription
fileFile | BlobThe file to process.
signalAbortSignalFires when the operation is cancelled — e.g. the upload was aborted or the file was removed. Pass it through to any async work that supports cancellation.

After a hook returns a different file, the uploader recalculates derived metadata such as file size, MIME type, image detection, and file name.

'onAdd' runs right after a file enters the uploader collection. Use it for light normalization that should happen as early as possible.

'beforeUpload' runs right before the file is sent to the Uploadcare API. This is the better place for heavier async work such as resizing, compression, or format conversion.

Warning: If a hook does not resolve within its timeout (default 30 seconds), the uploader skips it and continues with the original file. A timed-out hook is logged via debugPrint but does not block the upload.

Note: The helper functions in the examples below, such as detectMimeFromBytes and resizeImage, are illustrative placeholders. They are not provided by the uploader, so you need to implement them in your own code.

// onAdd — runs as soon as the file is added to the uploader
pluginApi.registry.registerFileHook({
type: 'onAdd',
async handler({ file }) {
if (file.type) return { file };
const detected = await detectMimeFromBytes(file);
const fileName = file instanceof File ? file.name : 'file';
return {
file: new File([file], fileName, { type: detected }),
};
},
});
// beforeUpload — runs right before upload, with cancellation and custom timeout
pluginApi.registry.registerFileHook({
type: 'beforeUpload',
timeout: 60_000, // allow up to 60s for heavy processing
async handler({ file, signal }) {
const resized = await resizeImage(file, { maxWidth: 1920, signal });
return { file: resized };
},
});

Multiple hooks of the same type are chained in registration order. Each handler receives the output of the previous one.


registerConfig

Declares a custom config option that becomes available on <uc-config> as a property (and optionally as an HTML attribute).

pluginApi.registry.registerConfig({
name: 'myApiKey',
defaultValue: '',
attribute: true, // expose as my-api-key="..." HTML attribute (default: true)
fromAttribute: (val) => val ?? '',
});
PropertyTypeRequiredDescription
namestringYescamelCase option name.
defaultValueTYesValue used when not explicitly set.
attributebooleanNoWhether to map to/from an HTML attribute. Default: true.
fromAttribute(value: string | null) => TNoParse attribute string to config value. Defaults to returning the raw string.
toAttribute(value: T) => string | nullNoSerialize config value to attribute string for reflection.
normalize(value: unknown) => TNoValidate or coerce values assigned via JavaScript property. Useful for clamping numbers or converting types.

Non-string config options

Use fromAttribute and normalize when the config value is not a plain string:

pluginApi.registry.registerConfig({
name: 'myMaxResults',
defaultValue: 24,
fromAttribute: (val) => (val !== null ? parseInt(val, 10) : 24),
normalize: (val) => (typeof val === 'number' && val > 0 ? val : 24),
});

TypeScript: declaring a custom config key

Augment the CustomConfig interface so pluginApi.config.get and .subscribe are typed:

declare module '@uploadcare/file-uploader' {
interface CustomConfig {
myApiKey: string;
}
}