-
Notifications
You must be signed in to change notification settings - Fork 3
/
safe.js
38 lines (36 loc) · 1.14 KB
/
safe.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
const imgLinks = [];
const uploadImages = () => {
let imagesLen = images.length;
images.forEach((image, index) => {
const storageRef = ref(storage, `Images/${Categories[category_Id]}/${image.name.split(/(\\|\/)/g).pop()}/`);
uploadBytes(storageRef, image).then(snapshot => getDownloadURL(snapshot.ref).then(url => {
imgLinks.push(url);
}))
.catch(error => {
setAlertMessage(error.message);
setAlertSeverity('error');
console.log(error);
})
.then(() => {
if (index === imagesLen - 1) uploadOnFirestore();
})
})
if (imagesLen === 0) uploadOnFirestore();
}
if (eventBrochure) {
const storageRef = ref(storage, `Brochure/${Categories[category_Id]}/${eventBrochure.name.split(/(\\|\/)/g).pop()}/`);
uploadBytes(storageRef, eventBrochure).then(snapshot => getDownloadURL(snapshot.ref).then(url => {
brochureUrl = url
desc += ` [Download event brochure](${url})`;
}))
.catch(error => {
setAlertMessage(error.message);
setAlertSeverity('error');
console.log(error);
})
.finally(() => {
uploadImages();
})
} else {
uploadImages();
}