File tree Expand file tree Collapse file tree 7 files changed +162
-6
lines changed Expand file tree Collapse file tree 7 files changed +162
-6
lines changed Original file line number Diff line number Diff line change 1818 <li ><a href =" /firestore/doc-component" ><Doc></a ></li >
1919 <li ><a href =" /firestore/collection-component" ><Collection></a ></li >
2020 <li class =" heading" >storage</li >
21- <li ><a href =" /guide/todo " >uploadTaskStore </a ></li >
22- <li ><a href =" /guide/todo " ><FileUploader ></a ></li >
23- <li ><a href =" /guide/todo " ><DownloadURL ></a ></li >
21+ <li ><a href =" /storage/upload-task " ><UploadTask> </a ></li >
22+ <li ><a href =" /storage/download-url " ><DownloadURL ></a ></li >
23+ <li ><a href =" /storage/storage-list " ><StorageList ></a ></li >
2424 <li class =" heading" >analytics</li >
2525 <li ><a href =" /guide/todo" ><PageView></a ></li >
2626 </ul >
Original file line number Diff line number Diff line change 1+ ---
2+ title : DownloadURL Component
3+ pubDate : 2023-07-23
4+ description : SvelteFire DownloadURL Component API reference
5+ layout : ../../layouts/MainLayout.astro
6+ ---
7+
8+ # DownloadURL
9+
10+ Returns the download URL for a file in Firebase Storage.
11+
12+ ### Props
13+
14+ - ` ref ` - A Firebase Storage reference or path string (e.g. ` files/hi-mom.txt ` )
15+
16+ ### Slots
17+
18+ - ` default ` - Shown when the url is available
19+ - ` loading ` - Shown while the url is loading
20+
21+ ### Slot Props
22+
23+ - ` link ` - The download URL
24+ - ` ref ` - Storage reference
25+ - ` storage ` - The Firestore instance
26+
27+ ### Example
28+
29+ ``` svelte
30+ <script>
31+ import { DownloadURL } from "sveltefire";
32+ </script>
33+
34+
35+ <DownloadURL ref="images/pic.png" let:link let:ref>
36+ <!-- show img -->
37+ <img src={link} />
38+
39+ <!-- or download via link -->
40+ <a href={link} download>{ref?.name}</a>
41+ </DownloadURL>
42+ ```
Original file line number Diff line number Diff line change 1+ ---
2+ title : StorageList Component
3+ pubDate : 2023-07-23
4+ description : SvelteFire StorageList Component API reference
5+ layout : ../../layouts/MainLayout.astro
6+ ---
7+
8+ # StorageList
9+
10+ Returns a list of files stored in Firebase Storage.
11+
12+ ### Props
13+
14+ - ` ref ` - A Firebase Storage reference or path string (e.g. ` files/hi-mom.txt ` )
15+
16+ ### Slots
17+
18+ - ` default ` - Shown when the list is available
19+ - ` loading ` - Shown while the list is loading
20+
21+ ### Slot Props
22+
23+ - ` list ` - The list of files and prefixes
24+ - ` ref ` - Storage reference
25+ - ` storage ` - The Firestore instance
26+
27+ ### Example
28+
29+ ``` svelte
30+ <script>
31+ import { StorageList } from "sveltefire";
32+ </script>
33+
34+
35+ <StorageList ref="images/uid" let:list>
36+ <ul>
37+ {#if list === null}
38+ <li>Loading...</li>
39+ {:else if list.prefixes.length === 0 && list.items.length === 0}
40+ <li>Empty</li>
41+ {:else}
42+ <!-- Listing the prefixes -->
43+ {#each list.prefixes as prefix}
44+ <li>
45+ {prefix.name}
46+ </li>
47+ {/each}
48+ <!-- Listing the objects in the given folder -->
49+ {#each list.items as item}
50+ <li>
51+ {item.name}
52+ </li>
53+ {/each}
54+ {/if}
55+ </ul>
56+ </StorageList>
57+ ```
Original file line number Diff line number Diff line change 1+ ---
2+ title : UploadTask Component
3+ pubDate : 2023-07-23
4+ description : SvelteFire UploadTask Component API reference
5+ layout : ../../layouts/MainLayout.astro
6+ ---
7+
8+ # UploadTask
9+
10+ Uploads a file to a Firebase storage bucket.
11+
12+ ### Props
13+
14+ - ` ref ` - A Firebase Storage reference or path string (e.g. ` files/hi-mom.txt ` )
15+ - ` data ` - the file data to be uploaded as ` Blob | Uint8Array | ArrayBuffer `
16+ - ` metadata ` - (optional) file metadata
17+
18+
19+ ### Slots
20+
21+ - ` default `
22+
23+ ### Slot Props
24+
25+ - ` snapshot ` - Firebase UploadTaskSnapshot
26+ - ` task ` - Firebase UploadTask
27+ - ` progress ` - Number as a percentage of the upload progress
28+ - ` storage ` - The Firestore instance
29+
30+ ### Example
31+
32+ ``` svelte
33+ <script>
34+ import { DownloadURL, UploadTask } from "sveltefire";
35+
36+ let file;
37+
38+ function chooseFile(e) {
39+ file = e.target.files[0];
40+ }
41+ </script>
42+
43+ <input type="file" on:change={chooseFile} />
44+
45+ {#if file}
46+ <UploadTask ref="myFile.txt" data={file} let:progress let:snapshot>
47+ {#if snapshot?.state === "running"}
48+ {progress}% uploaded
49+ {/if}
50+
51+ {#if snapshot?.state === "success"}
52+ <DownloadURL ref={snapshot?.ref} let:link>
53+ <a href={link} download>Link</a>
54+ </DownloadURL>
55+ {/if}
56+ </UploadTask>
57+ {/if}
58+ ```
Original file line number Diff line number Diff line change 11{
22 "name" : " sveltefire" ,
3- "version" : " 0.4.1 " ,
3+ "version" : " 0.4.2 " ,
44 "scripts" : {
55 "dev" : " vite dev" ,
66 "build" : " vite build && npm run package" ,
Original file line number Diff line number Diff line change 1- import { writable } from "svelte/store" ;
21import type { Firestore } from "firebase/firestore" ;
32import type { Auth } from "firebase/auth" ;
43import { getContext , setContext } from "svelte" ;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ test('Renders download links', async ({ page }) => {
88 expect ( linksCount ) . toBeGreaterThan ( 0 ) ;
99} ) ;
1010
11- test . only ( 'Uploads a file' , async ( { page } ) => {
11+ test ( 'Uploads a file' , async ( { page } ) => {
1212 await page . goto ( '/storage-test' ) ;
1313 await page . getByRole ( 'button' , { name : 'Make File' } ) . click ( ) ;
1414 await expect ( page . getByTestId ( 'progress' ) ) . toContainText ( '100% uploaded' ) ;
You can’t perform that action at this time.
0 commit comments