I am trying to upload multiple images to Firebase storage. the issue I have is trying to retrieve the Url's for each of the images. the files itself upload successfully if I do not try to retrieve the Url's the issue i see happening is that the upload runs in parallel to the url's being generated and hence there isnt an update to the url by the time it gets to the second image.
the error i get is "[firebase_storage/object-not-found] No object exists at the desired reference."
Note: I am not using forEach because i am limiting the number of files to upload to 5. the code below is contained within a if statement to check the list length.
for (var i = 0; i < _imageFileList!.length; i++) {
if (kIsWeb) {
var bytes = await _imageFileList![i].readAsBytes();
print('photo$i');
Reference snapshot = await FirebaseStorage.instance.ref().child('items/$itemkey/photo$i');
UploadTask uploadFile = snapshot.putData(bytes);
// If I delete the following 2 lines then the uploadof multiple files works without any issues.
imagesUrls.add(await (snapshot.getDownloadURL()));
print(imagesUrls);
///// ///// ///// ///// ///// /////
} else {
String filePath = 'items/${itemkey}/photo${i}.jpg';
Reference snapshot = FirebaseStorage.instance.ref().child(filePath);
UploadTask uploadFile = snapshot.putFile(File(_imageFileList![i].path));
// currently doesnt work but testing on web so this doesnt trigger.
final String downloadUrl = await snapshot.getDownloadURL();
print(downloadUrl);
//////////////////////////////////
}
}
How do I get these to run async or await? i can't put await in front of the for loop because flutter tells me i cant use await for a normal for loop.