0

I have an array of image files that I loop over and convert each element (file) to a download url, which is basically a string.
So why do I get Unsupported field value: a custom File object error when I try to push this array to Firestore.

Note: Not everytime I use set it gives me an error. Sometimes it works, which is confusing too.

images.forEach((file, index) => {
  const storageRef = firebase.storage().ref(`products/${uuid}.${fileExtenstion}`);
  const task = storageRef.put(file);
  task.on('state_changed', 
    function progress() {},
    function error() {},
    function complete() {
      storageRef.getDownloadURL().then(url => {
        imageFiles[index] = url;
      })
    }
  )
})

firestore.collection('products').doc().set({
  images: images
});
Moaaz Bhnas
  • 1,010
  • 7
  • 18
  • 36
  • 4
    i think it's just a matter of asynchronous nature of the javascript and not every task being completed before you try to set images – Krzysztof Krzeszewski May 15 '20 at 13:06
  • Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Krzysztof Krzeszewski May 15 '20 at 14:01

0 Answers0