-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase.js
43 lines (34 loc) · 1.26 KB
/
firebase.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
import * as firebase from 'firebase/app';
import 'firebase/storage';
const firebaseConfig = {
apiKey: "AIzaSyCkSnp_djsV1iTN-bin9V2m6vfqMrRsprE",
authDomain: "food-delivery-mobile-app.firebaseapp.com",
databaseURL: "https://food-delivery-mobile-app.firebaseio.com",
projectId: "food-delivery-mobile-app",
storageBucket: "food-delivery-mobile-app.appspot.com",
messagingSenderId: "942500859417",
appId: "1:942500859417:web:88ceaced3015ddb1a66488"
};
export const onImageUploadHandler = async (imageUri, userId) =>{
// create blob with the imageuri
const blob = await new Promise ((resolve, reject)=>{
const xhr = new XMLHttpRequest();
xhr.onload = () => {
resolve(xhr.response);
};
xhr.onerror = (e) => {
reject(new TypeError('Network request failed'));
};
xhr.responseType = 'blob';
xhr.open('GET', imageUri, true);
xhr.send(null);
})
// CREATE A STORAGE REF
const storageRef = firebase.storage().ref(`users_image/${userId}`);
// UPLOAD FILE
const snapshot = await storageRef.put(blob);
// We're done with the blob, close and release it
blob.close();
return await snapshot.ref.getDownloadURL();
}
firebase.initializeApp(firebaseConfig);