Skip to content

Repository files navigation

svelte-firebase-upload

File upload manager for Svelte 5 + Firebase Storage. Concurrent uploads, resumable transfers, file validation, and a Dropbox-style upload panel — zero extra dependencies.

Install

npm install svelte-firebase-upload firebase

Quick Start

<script>import { initializeApp } from'firebase/app';import { getStorage } from'firebase/storage';import { FirebaseUploadManager, UploadPanel, UploadDropZone } from'svelte-firebase-upload';constapp=initializeApp({ /* your config */ });conststorage=getStorage(app);constmanager=newFirebaseUploadManager({ maxConcurrentUploads:3, autoStart:true });manager.setStorage(storage);let showPanel =$state(true);</script>
<UploadDropZoneuploadManager={manager} accept="image/*,.pdf" />
<UploadPaneluploadManager={manager} bind:visible={showPanel} />

Features

  • Concurrent uploads with configurable concurrency limits
  • Resumable transfers with chunk-based recovery
  • File validation — size limits, type checks, duplicate detection, security scanning
  • Dropbox-style UI — floating panel with progress, tabs, per-file actions
  • Drag & drop zone — standalone component with file filtering
  • Error handling — stall detection, toast notifications, retry with backoff
  • Network awareness — monitors connection quality, adapts to conditions
  • Bandwidth throttling — adaptive rate limiting
  • Plugin system — extensible hooks for every upload lifecycle event
  • SSR safe — all browser APIs guarded for SvelteKit
  • Themeable — CSS custom properties for full visual control
  • TypeScript — fully typed API

Components

UploadPanel

Floating panel that shows upload progress, errors, and per-file actions.

<UploadPaneluploadManager={manager}
bind:visible={showPanel}
position="bottom-right"onerror={(item, error) =>console.log('Failed:', item.file.name)}
/>
PropTypeDefaultDescription
uploadManagerFirebaseUploadManagerrequiredManager instance
visiblebooleantrueBindable show/hide
position'bottom-right' | 'bottom-left''bottom-right'Panel position
onerror(item, error) => voidError callback

UploadDropZone

Drag & drop area with click-to-browse. Supports custom content via slot.

<UploadDropZoneuploadManager={manager}
accept="image/*,.pdf"path="user-uploads/"maxSize={10*1024*1024}
/>
PropTypeDefaultDescription
uploadManagerFirebaseUploadManagerrequiredManager instance
acceptstring''File type filter
multiplebooleantrueAllow multiple files
maxSizenumberMax file size (bytes)
pathstring'uploads/'Storage directory
disabledbooleanfalseDisable interaction

Manager API

constmanager=newFirebaseUploadManager({maxConcurrentUploads: 5,// default: 5chunkSize: 5*1024*1024,// default: 5MBretryAttempts: 3,// default: 3retryDelay: 1000,// default: 1000msautoStart: true,// default: falseenableSmartScheduling: true// default: false});manager.setStorage(storage);// Add filesawaitmanager.addFiles(fileList,{path: 'photos/'});// Controlawaitmanager.start();awaitmanager.pause();awaitmanager.resume();awaitmanager.stop();// Validationconstresults=awaitmanager.validateFiles(files,{maxSize: 10*1024*1024,allowedTypes: ['image/*','.pdf']});// State (all reactive with $state)manager.totalProgress// 0-100manager.currentSpeed// bytes/secmanager.successCountmanager.failureCountmanager.isProcessingmanager.queuemanager.failedmanager.completed

Plugins

import{LoggingPlugin,AnalyticsPlugin}from'svelte-firebase-upload';awaitmanager.registerPlugin(newLoggingPlugin({logLevel: 'info'}));awaitmanager.registerPlugin(newAnalyticsPlugin());

Built-in presets: LoggingPlugin, AnalyticsPlugin, FileProcessingPlugin, ValidationEnhancementPlugin, QueueOptimizationPlugin.

Theming

Override CSS custom properties to match your design:

:root {
--sfu-panel-bg:#ffffff;
--sfu-panel-border:#e5e7eb;
--sfu-panel-shadow:025px50px-12pxrgba(0,0,0,0.25);
--sfu-text-primary:#111827;
--sfu-text-secondary:#6b7280;
--sfu-progress-bg:#e5e7eb;
--sfu-progress-fill:#3b82f6;
--sfu-success:#22c55e;
--sfu-error:#ef4444;
--sfu-warning:#f59e0b;
--sfu-radius:12px;
--sfu-font-family: system-ui, -apple-system, sans-serif;
}

Firebase Setup

Your storage bucket needs CORS configured for local development:

[{
"origin": ["http://localhost:5173"],
"method": ["GET", "POST", "PUT", "DELETE", "HEAD"],
"maxAgeSeconds": 3600,
"responseHeader": ["Content-Type", "Authorization", "Content-Length", "User-Agent", "x-goog-resumable"]
}]

Apply with: gcloud storage buckets update gs://YOUR_BUCKET --cors-file=cors.json

License

MIT

About

File upload manager for Svelte 5 + Firebase Storage. Concurrent uploads, resumable transfers, file validation, and a Dropbox-style upload panel — zero extra dependencies.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages