Core module for the extensible JavaScript file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Instagram, Dropbox, Google Drive, S3 and more
—
The Uppy class is the central component of the Uppy ecosystem, providing complete file upload management, state handling, plugin orchestration, and event coordination.
constructor(opts?: UppyOptions<M, B>)interface UppyOptions<M extends Meta = Meta, B extends Body = Body> {
id?: string; // Instance identifier (default: 'uppy')
autoProceed?: boolean; // Auto-start uploads (default: false)
allowMultipleUploadBatches?: boolean; // Allow multiple batches (default: true)
debug?: boolean; // Enable debug logging (default: false)
restrictions?: Partial<Restrictions>; // File restrictions
meta?: Partial<M>; // Default file metadata
locale?: Locale; // Localization settings
store?: Store; // Custom state store
logger?: typeof debugLogger; // Custom logger
infoTimeout?: number; // Info message duration (default: 5000ms)
onBeforeFileAdded?: (
currentFile: UppyFile<M, B>,
files: { [key: string]: UppyFile<M, B> }
) => boolean | Promise<boolean>;
onBeforeUpload?: (
files: { [key: string]: UppyFile<M, B> }
) => boolean | Promise<boolean>;
}static VERSION: string; // Package versiongetState(): State<M, B>;
setState(patch?: Partial<State<M, B>>): void;setFileState(fileID: string, state: Partial<UppyFile<M, B>>): void;
patchFilesState(filesWithNewState: {
[id: string]: Partial<UppyFile<M, B>>
}): void;setOptions(newOpts: Partial<UppyOptions<M, B>>): void;addFile(file: File | MinimalRequiredUppyFile<M, B>): string;
addFiles(fileDescriptors: MinimalRequiredUppyFile<M, B>[]): void;Parameters:
file: Browser File object or minimal file descriptorfileDescriptors: Array of file descriptorsReturns: addFile returns the generated file ID
removeFile(fileID: string): void;
removeFiles(fileIDs: string[]): void;getFile(fileID: string): UppyFile<M, B>;
getFiles(): UppyFile<M, B>[];
getFilesByIds(ids: string[]): UppyFile<M, B>[];
getObjectOfFilesPerState(): {
newFiles: UppyFile<M, B>[];
startedFiles: UppyFile<M, B>[];
uploadStartedFiles: UppyFile<M, B>[];
pausedFiles: UppyFile<M, B>[];
completeFiles: UppyFile<M, B>[];
erroredFiles: UppyFile<M, B>[];
inProgressFiles: UppyFile<M, B>[];
inProgressNotPausedFiles: UppyFile<M, B>[];
processingFiles: UppyFile<M, B>[];
isUploadStarted: boolean;
isAllComplete: boolean;
isAllErrored: boolean;
isAllPaused: boolean;
isUploadInProgress: boolean;
isSomeGhost: boolean;
};checkIfFileAlreadyExists(fileID: string): boolean;upload(): Promise<UploadResult<M, B> | undefined>;Returns: Promise resolving to upload result with successful/failed file counts and file data
pauseResume(fileID: string): boolean | undefined;
pauseAll(): void;
resumeAll(): void;Parameters:
fileID: Specific file to pause/resumeReturns: pauseResume returns the new paused state (true/false) or undefined if file not found
retryAll(): Promise<UploadResult<M, B> | undefined>;
retryUpload(fileID: string): Promise<UploadResult<M, B> | undefined>;cancelAll(): void;on<K extends keyof UppyEventMap<M, B>>(
event: K,
callback: UppyEventMap<M, B>[K]
): this;
once<K extends keyof UppyEventMap<M, B>>(
event: K,
callback: UppyEventMap<M, B>[K]
): this;
off<K extends keyof UppyEventMap<M, B>>(
event: K,
callback: UppyEventMap<M, B>[K]
): this;emit<K extends keyof UppyEventMap<M, B>>(
event: K,
...args: Parameters<UppyEventMap<M, B>[K]>
): void;validateRestrictions(
file: ValidateableFile<M, B>,
files?: ValidateableFile<M, B>[]
): RestrictionError<M, B> | null;
validateSingleFile(file: ValidateableFile<M, B>): string | null;
validateAggregateRestrictions(
files: ValidateableFile<M, B>[]
): string | null;Parameters:
file: File to validatefiles: All files for aggregate validationReturns: Error object/message if validation fails, null if valid
setMeta(data: Partial<M>): void;setFileMeta(fileID: string, data: Partial<M>): void;use<T extends typeof BasePlugin<any, M, B>>(
Plugin: T,
...args: OmitFirstArg<ConstructorParameters<T>>
): this;getPlugin<T extends UnknownPlugin<M, B> = UnknownPlugin<M, B>>(
id: string
): T | undefined;
iteratePlugins(method: (plugin: UnknownPlugin<M, B>) => void): void;removePlugin(instance: UnknownPlugin<M, B>): void;addPreProcessor(fn: Processor): void;
removePreProcessor(fn: Processor): boolean;addUploader(fn: Processor): void;
removeUploader(fn: Processor): boolean;addPostProcessor(fn: Processor): void;
removePostProcessor(fn: Processor): boolean;Processor Type:
type Processor = (
fileIDs: string[],
uploadID: string
) => Promise<unknown> | void;getID(): string;
clear(): void;
resetProgress(): void;
destroy(): void;restore(uploadID: string): Promise<UploadResult<M, B> | undefined>;
addResultData(uploadID: string, data: any): void;registerRequestClient(id: string, client: unknown): void;
getRequestClientForFile<Client>(file: UppyFile<M, B>): Client;
logout(): void;info(
message: string | { message: string; details: string },
type?: 'info' | 'warning' | 'error' | 'success',
duration?: number
): void;
hideInfo(): void;
log(message: unknown, type?: 'error' | 'warning'): void;updateOnlineStatus(): void;opts: UppyOptions<M, B>; // Current options
store: Store; // State store instance
locale: Locale; // Current locale
i18n: I18n; // Translation function
i18nArray: Translator['translateArray']; // Array translationimport Uppy from '@uppy/core';
const uppy = new Uppy({
restrictions: {
maxFileSize: 5 * 1024 * 1024, // 5MB
allowedFileTypes: ['image/*']
}
});
// Add event listeners
uppy.on('file-added', (file) => {
console.log('File added:', file.name);
});
uppy.on('upload-success', (file, response) => {
console.log('Upload successful:', file.name, response);
});
// Add files and upload
const fileInput = document.querySelector('#file-input');
fileInput.addEventListener('change', (event) => {
const files = Array.from(event.target.files);
files.forEach(file => uppy.addFile(file));
uppy.upload();
});const uppy = new Uppy({
onBeforeFileAdded: (currentFile, files) => {
// Custom validation logic
if (currentFile.name.includes('temp')) {
uppy.info('Temporary files are not allowed', 'error');
return false;
}
return true;
},
onBeforeUpload: (files) => {
// Pre-upload validation
const fileCount = Object.keys(files).length;
if (fileCount === 0) {
uppy.info('Please select at least one file', 'error');
return false;
}
return true;
}
});import Uppy from '@uppy/core';
import Dashboard from '@uppy/dashboard';
import XHRUpload from '@uppy/xhr-upload';
const uppy = new Uppy()
.use(Dashboard, {
target: '#uppy-dashboard',
inline: true
})
.use(XHRUpload, {
endpoint: '/upload',
headers: {
'Authorization': 'Bearer token'
}
});Install with Tessl CLI
npx tessl i tessl/npm-uppy--core