-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathUploadTask.svelte
35 lines (30 loc) · 1.07 KB
/
UploadTask.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<script lang="ts">
import { uploadTaskStore } from "$lib/stores/storage.js";
import { getFirebaseContext } from "$lib/stores/sdk.js";
import type {
FirebaseStorage,
UploadTask,
StorageReference,
UploadMetadata,
UploadTaskSnapshot,
} from "firebase/storage";
export let ref: string | StorageReference;
export let data: Blob | Uint8Array | ArrayBuffer;
export let metadata: UploadMetadata | undefined = undefined;
const { storage } = getFirebaseContext();
const upload = uploadTaskStore(storage!, ref, data, metadata);
interface $$Slots {
default: {
task: UploadTask | undefined;
error: Error | null;
ref: StorageReference | null;
snapshot: UploadTaskSnapshot | null;
progress: number;
storage?: FirebaseStorage;
};
}
$: progress = ($upload?.data?.bytesTransferred! / $upload?.data?.totalBytes!) * 100 ?? 0;
</script>
{#if $upload !== undefined && $upload !== null}
<slot task={$upload?.data?.task} error={$upload?.error} snapshot={$upload.data} {progress} ref={upload.reference} {storage} />
{/if}