Flutter Upload batch of images and get all those URLs to store in Firestore

upload multiple images to firebase android
flutter upload multiple images
firebase storage get download url after upload
flutter upload image to firebase storage
flutter firebase storage download file
firebase-storage dependency
flutter multi_image_picker upload
upload multiple images in firebase flutter

I'm trying to upload n number of photos to Firebase Storage and save those URLs in an array inside Firestore, but I am not able to get the downloadURL() or I do not know where to find it rather. I've checked other answers but those were for single files, I'm trying to upload a batch and store the URLs together instead of uploading on and storing the URL to Firestore and so on and so forth...

CODE:

_uploadImages(String userID, String productID, List<File> images, Function onSuccess(List<String> imageURLs), Function onFailure(String e)) {
    List<String> imageURLs = [];
    int uploadCount = 0;

    StorageReference storeRef = FirebaseStorage.instance.ref().child('Products').child(userID).child(productID).child(uploadCount);
    StorageMetadata metaData = StorageMetadata(contentType: 'image/png');

    images.forEach((image) {
      storeRef.putFile(image, metaData).onComplete.then((snapshot) {
        STUCK AT THIS POINT SINCE THE SNAPSHOT DOESN'T SHOW THE URL OPTION...
        //imageURLs.add(snapshot. )
        uploadCount++;

        if (uploadCount == images.length) {
          onSuccess(imageURLs);
        }
      });
    });
  }

You could use this method for multiple file upload to firebase storage where List<Asset> assets are your List<File> files.

Future<List<String>> uploadImage(
      {@required String fileName, @required List<Asset> assets}) async {
    List<String> uploadUrls = [];

    await Future.wait(assets.map((Asset asset) async {
      ByteData byteData = await asset.requestOriginal();
      List<int> imageData = byteData.buffer.asUint8List();

      StorageReference reference = FirebaseStorage.instance.ref().child(fileName);
      StorageUploadTask uploadTask = reference.putData(imageData);
      StorageTaskSnapshot storageTaskSnapshot;

      // Release the image data
      asset.releaseOriginal();

      StorageTaskSnapshot snapshot = await uploadTask.onComplete;
      if (snapshot.error == null) {
        storageTaskSnapshot = snapshot;
        final String downloadUrl = await storageTaskSnapshot.ref.getDownloadURL();
        uploadUrls.add(downloadUrl);

        print('Upload success');
      } else {
        print('Error from image repo ${snapshot.error.toString()}');
        throw ('This file is not an image');
      }
    }), eagerError: true, cleanUp: (_) {
     print('eager cleaned up');
    });

    return uploadUrls;
}

Upload Image File To Firebase Storage Using Flutter, If you are interested in the chat app, you can check out my whole series. a simple app to upload the user-selected image uploaded to Firebase Storage and For File Upload To Firestore; import 'package:flutter/material.dart';; import using file picker and uploadedFileURL will stores the uploaded file url. Run Flutter packages that you can get in terminal OR If you are using Visual Studio Code then after saving the file it will automatically run the Flutter packages get command. Step 2 Now, open main.dart file under lib folder.


Try this (inside onComplete):

storeRef.getDownloadURL() 

Hello everyone, Today we will learn how to pick multiple images , Today we will learn how to pick multiple images, upload them on firebase, fetch​… It will be used to store URLs of images. cloud_firestore | Flutter Package. A Flutter plugin to use the Cloud Firestore API. Let's have a look at how it is made​. borderRadius: BorderRadius.all(Radius.circular(15)), The flutter image download and display development tutorial describes, how to download a remote image and then display it in the flutter application. This flutter development tutorial will include


I tried the marked answer didnt work for me so i dug deep and managed to do it with a for loop

 List<File> _imageList = List();
//add selected images to list
 _imageList.add(_image);
      Future uploadMultipleImages() async {

    List<String> _imageUrls = List();




    try {
      for (int i = 0; i < _imageList.length; i++) {
        final StorageReference storageReference = FirebaseStorage().ref().child("multiple2/$i");

        final StorageUploadTask uploadTask = storageReference.putFile(_imageList[i]);

        final StreamSubscription<StorageTaskEvent> streamSubscription =
            uploadTask.events.listen((event) {
          // You can use this to notify yourself or your user in any kind of way.
          // For example: you could use the uploadTask.events stream in a StreamBuilder instead
          // to show your user what the current status is. In that case, you would not need to cancel any
          // subscription as StreamBuilder handles this automatically.

          // Here, every StorageTaskEvent concerning the upload is printed to the logs.
          print('EVENT ${event.type}');
        });

        // Cancel your subscription when done.
        await uploadTask.onComplete;
        streamSubscription.cancel();

        String imageUrl = await storageReference.getDownloadURL();
        _imageUrls.add(imageUrl); //all all the urls to the list
      }
      //upload the list of imageUrls to firebase as an array
      await _firestore.collection("users").document("user1").setData({
        "arrayOfImages": _imageUrls,
      });
    } catch (e) {
      print(e);
    }
  }

you can check more from this github project

Upload Files on Web, Get a download URL. After uploading a file, you can get a URL to download the file by calling the getDownloadUrl() method on the StorageReference :. This video ties all of those previous concepts together, so that we can effectively store large files in Firebase, and access them from a database. To do this, we have to 1) add a blank URL to the


Upload Files on Android, Uploading multiple images to firebase and getting links of all of them As we know that it's not advisable to store images in Firestore, best alternative is to for its url and storing it in another array which I wish to put in Firestore along with other In my current project, my client app (created in Flutter) performs several REST  Cloud Firestore Plugin for Flutter # A Flutter plugin to use the Cloud Firestore API. For Flutter plugins for other Firebase products, see README.md. Setup # To use this plugin: Add cloud_firestore as a dependency in your pubspec.yaml file. Android # Using the Firebase Console, add an Android app to your project.


Uploading multiple images to firebase and getting links of all of them , How to upload multiple images into firestore flutter I am today teach you how to with the mentioned task. you can get all types flutter tutorials from this links. in detail in the article Uploading Files With . be Upload and store image in the Define assets to be used in pubspec. network, for obtaining an image from a URL​. #Google's Flutter Tutorial - Upload Image to Server using PHP (coderzheaven.com) - Duration: 11:50. The Mobile Programmer 9,179 views


Flutter - Upload files to Firebase Storage, Scale: Every file uploaded is backed by Google Cloud Storage, which case of poor network connections, so you don't have to keep track of them yourself. fromFile(new File("path/to/images/file.jpg")); UploadTask uploadTask = storageRef. The web SDK can download files just from a download URL. For example, if a transaction reads documents and another client modifies any of those documents, Cloud Firestore retries the transaction. This feature ensures that the transaction runs on up-to-date and consistent data. Transactions never partially apply writes. All writes execute at the end of a successful transaction.