title: Upload Folder of Images to Firestore Storage and Put Download URLs in Firestore
body: <p>I have roughly 10,000 images that I want to upload to Firebase Storage (it adds up to around 800mb). </p>
  
  <p>Using Javascript, I am looking for a way to:</p>
  
  <ol>
  <li>Upload them to Firebase Storage</li>
  <li>Grab their URL upon upload and create Cloud Firestore documents for each using their file names with a field called "downloadURL" or something like that that my website can then use for  tags.</li>
  </ol>
  
  <p>So say one file is 4670.jpg. I want to upload the file, grab its persistent URL and then create a Cloud Firestore document called 4670 that has a text field with it's persistent URL. I know how to do this for a single file, but I'm dealing with thousands.</p>
  
  <p><strong>Edit: A huge thanks for, Renaud Tarnec who gave me a working solution</strong></p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>// File selector
  
  &lt;input type="file" multiple onchange="processSelectedFiles(this)"&gt;
  
  // CDN for Firebase, Cloud Firestore, and Firebase Storage
  &lt;script src="https://www.gstatic.com/firebasejs/4.12.0/firebase.js"&gt;&lt;/script&gt;
  &lt;script src="https://www.gstatic.com/firebasejs/4.11.0/firebase-firestore.js"&gt;&lt;/script&gt;
  &lt;script src="https://www.gstatic.com/firebasejs/4.12.0/firebase-storage.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
    // Initialize Firebase
    var config = {
      apiKey: "********************",
      authDomain: "********************",
      databaseURL: "********************",
      projectId: "********************",
      storageBucket: "********************",
      messagingSenderId: "********************"
    };
    firebase.initializeApp(config);
  
  
  var db = firebase.firestore();
  
  &lt;/script&gt;
  
  &lt;script src="script.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p><strong>Javascript</strong></p>
  
  <pre><code>function processSelectedFiles(fileInput) {
    var files = fileInput.files;
  
    var promises = []
  
    for (var i = 0; i &lt; files.length; i++) {
  
      var file = files[i] 
  
        promises.push(uploadAndSavePromise(file))
    }
  
      Promise.all(promises);
  }
  
  function uploadAndSavePromise(file) {
       var storageRef = firebase.storage().ref();
       var fileName = file.name
       // Remove extension
       var trimmedFileName = fileName.slice(0, -4)
  
       var imageRef = storageRef.child('test/'+fileName);
  
      return imageRef.put(file).then(function(snapshot) {
  
          db.collection("maincollection").doc(trimmedFileName).set({
          imageURL: snapshot.downloadURL,
  
  })
  
  });
  
  }
  </code></pre>