-
Notifications
You must be signed in to change notification settings - Fork 240
/
storage_download_full_example.js
40 lines (35 loc) · 1.17 KB
/
storage_download_full_example.js
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
36
37
38
39
40
// This snippet file was generated by processing the source file:
// ./storage-next/download-files.js
//
// To update the snippets in this file, edit the source and then run
// 'npm run snippets'.
// [START storage_download_full_example_modular]
import { getStorage, ref, getDownloadURL } from "firebase/storage";
// Create a reference to the file we want to download
const storage = getStorage();
const starsRef = ref(storage, 'images/stars.jpg');
// Get the download URL
getDownloadURL(starsRef)
.then((url) => {
// Insert url into an <img> tag to "download"
})
.catch((error) => {
// A full list of error codes is available at
// https://firebase.google.com/docs/storage/web/handle-errors
switch (error.code) {
case 'storage/object-not-found':
// File doesn't exist
break;
case 'storage/unauthorized':
// User doesn't have permission to access the object
break;
case 'storage/canceled':
// User canceled the upload
break;
// ...
case 'storage/unknown':
// Unknown error occurred, inspect the server response
break;
}
});
// [END storage_download_full_example_modular]