Skip to content

Plugins

The plugin system provides hooks into every upload lifecycle event. Register plugins to add logging, analytics, file processing, validation, and queue optimization.

import {
FirebaseUploadManager,
LoggingPlugin,
AnalyticsPlugin
} from 'svelte-firebase-upload';
const manager = new FirebaseUploadManager();
await manager.registerPlugin(new LoggingPlugin({ logLevel: 'info' }));
await manager.registerPlugin(new AnalyticsPlugin());
// Enable/disable — use the plugin's .name property, not the class name
await manager.setPluginEnabled('logging', false);
// Unregister
await manager.unregisterPlugin('logging');
// List all
manager.getAllPlugins(); // [{ name, plugin, config }]
manager.getEnabledPlugins(); // Only active ones

Logs all upload events to the console and optionally to storage.

const logger = new LoggingPlugin({
logLevel: 'info', // 'debug' | 'info' | 'warn' | 'error'
logToConsole: true,
logToStorage: false
});
await manager.registerPlugin(logger);
// Access logs
logger.getLogs();
logger.clearLogs();

Implement the UploadPlugin interface to create your own:

import type { UploadPlugin, UploadItem, ValidationResult } from 'svelte-firebase-upload';
const myPlugin: UploadPlugin = {
name: 'MyCustomPlugin',
version: '1.0.0',
description: 'Does something custom',
// Lifecycle hooks
async onInitialize(manager) {
console.log('Plugin initialized');
},
async onDestroy() {
console.log('Plugin destroyed');
},
// File hooks — modify file/options before adding
async beforeFileAdd(file, options) {
return { file, options }; // Return modified or original
},
async afterFileAdd(item) {},
// Validation hooks
async beforeValidation(file, rules) {
return { file, rules };
},
async afterValidation(file, result) {},
// Upload hooks
async beforeUpload(item) {
return item; // Return modified or original
},
async onUploadStart(item) {},
async onUploadProgress(item, progress) {},
async onUploadComplete(item, result) {},
async onUploadError(item, error) {},
// Queue hooks
async beforeQueueProcess(queue) {
return queue; // Reorder or filter
},
async afterQueueProcess(queue) {},
// State hooks
async onStatusChange(item, oldStatus, newStatus) {},
async onManagerStateChange(state) {},
async onError(error, context) {},
};
await manager.registerPlugin(myPlugin);
EventWhen it fires
beforeFileAddBefore a file is added to the queue
afterFileAddAfter a file is added to the queue
beforeValidationBefore file validation runs
afterValidationAfter validation completes
beforeUploadBefore upload starts
onUploadStartWhen upload begins
onUploadProgressOn progress update
onUploadCompleteWhen upload succeeds
onUploadErrorWhen upload fails
beforeQueueProcessBefore the queue is processed
afterQueueProcessAfter queue processing
onStatusChangeWhen a file’s status changes
onManagerStateChangeWhen manager state changes
onErrorOn any error