Using Firebase to upload images

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 =;
for (var i = 0; i < length; i++) {
const ref =${lehrerKuerzel}/${klasse}/${abteilung}/${pruefungsName}/${date}/${i});
ref.putString([i], ‘data_url’).then((snapshot) => {
var db = firebase.firestore().collection(${lehrerKuerzel});
TestName: pruefungsName,
Klasse: klasse,
Abteilung: abteilung,
Datum: date,
DownloadURLs: testArray,
Length: length,