-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (37 loc) · 1.35 KB
/
app.js
File metadata and controls
43 lines (37 loc) · 1.35 KB
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
import firebase from 'firebase/app'
import 'firebase/storage'
import {upload} from './upload.js'
var firebaseConfig = {
apiKey: "AIzaSyAeBRl5xgE38y73PVccmbhNPyGdBj-GRik",
authDomain: "fe-upload-6c2f9.firebaseapp.com",
projectId: "fe-upload-6c2f9",
storageBucket: "fe-upload-6c2f9.appspot.com",
messagingSenderId: "1032354531852",
appId: "1:1032354531852:web:b9143101c45a27cce23c29"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const storage = firebase.storage()
upload('#file', {
multi: true,
accept: ['.png', '.jpg', '.jpeg', '.gif'],
onUpload(files, blocks){
files.forEach((file, index) => {
const ref = storage.ref(`images/${file.name}`)
const task = ref.put(file)
task.on('state_changed', snapshot => {
const percentage = ((snapshot.bytesTransferred / snapshot.totalBytes) * 100).toFixed(0) + '%';
const block = blocks[index].querySelector('.preview-info-progress');
block.textContent = percentage;
block.style.width = percentage ;
}, error =>{
}, () => {
task.snapshot.ref.getDownloadURL().then(url => {
console.log('download URL', url);
})
console.log('Complete');
})
});
console.log('Files:', files);
}
});