Using Firebase to upload images


#1

Hi, I’m developing an Ionic app that takes pictures and uploads them to firebase. As I later want to be able to search for these pictures, I have tried to implement a database using firesbase firestore. However, the array I’m using seems to be causing some issues. When I upload for the first time to firebase, nothing shows up, if I push the button a second time, it’s all there. Here’s my code:

uploadForm() {
var testArray = [];
var kuerzel = this.exam.kuerzel;
var lehrerKuerzel = kuerzel.toUpperCase();
var pruefungsName = this.exam.pruefungsName;
var klasse = this.exam.klasse;
var abteilung = this.exam.abteilung;
var date = Date();
var length = this.photos.length;
for (var i = 0; i < length; i++) {
const ref = firebase.storage().ref(pruefungen/${lehrerKuerzel}/${klasse}/${abteilung}/${pruefungsName}/${date}/${i});
ref.putString(this.photos[i], ‘data_url’).then((snapshot) => {
testArray.push(snapshot.downloadURL);
});
}
var db = firebase.firestore().collection(${lehrerKuerzel});
db.add({
TestName: pruefungsName,
Klasse: klasse,
Abteilung: abteilung,
Datum: date,
DownloadURLs: testArray,
Length: length,
});

}