-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstorage.js
55 lines (43 loc) · 1.32 KB
/
storage.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(function(){
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "apple",
authDomain: "pear",
projectId: "grape",
storageBucket: "guava",
messagingSenderId: "kiwi",
appId: "peach"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// Create a root reference
var storage = firebase.storage();
var storageRef = storage.ref();
// get elements
const file = document.getElementById('file');
const upload = document.getElementById('upload');
const download = document.getElementById('download');
const status = document.getElementById('status');
const image = document.getElementById('image');
// upload file
upload.addEventListener('click', e => {
// Create a file reference
var ref = storageRef.child('globe');
let photo = document.getElementById("file").files[0];
// upload
ref.put(photo).then(function(snapshot) {
console.log('Uploaded a blob or file!');
status.innerHTML = 'Uploaded blob or file!'
});
});
// download file
download.addEventListener('click', e => {
// file reference
var ref = storage.ref('globe');
ref.getDownloadURL().then(function(url) {
// insert url into an <img> tag to "download"
image.src = url;
status.innerHTML = 'Downloaded blob or file!'
}).catch(function(error){console.log(error)});
});
}());