firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

Cloud firestore cannot store my firebase storage image url

Open eakrum opened this issue 8 years ago • 1 comments

  • Operating System version: iOS 11.2 React Native 0.53.3
  • Firebase SDK version: 4.10.0
  • Firebase Product: storage, firestore
getSelectedImages = (selectedImages, currentImage) => {
    
    const image = currentImage.uri
 
    const Blob = RNFetchBlob.polyfill.Blob
    const fs = RNFetchBlob.fs
    window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
    window.Blob = Blob
 
   
    let uploadBlob = null;
    const imageRef = firebase.storage().ref('profile-Photos').child(firebase.auth().currentUser.email + '.jpg');
    let mime = 'image/jpg';
    
    

    //THIS ADDS IMAGE TO FIRE STORAGE AND PULLS URL
    fs.readFile(image, 'base64')
      .then((data) => {
        return Blob.build(data, { type: `${mime};BASE64` })
    })
    .then((blob) => {
        uploadBlob = blob
        return imageRef.put(blob, { contentType: mime })
      })
      .then(() => {
        uploadBlob.close()
        return imageRef.getDownloadURL()
      })
      .then((url) => {
        // URL of the image uploaded on Firebase storage
        console.log('my url is' , url);
        this.setState({profPic: url})
        console.log('new prof pic:', this.state.profPic)
        
        
      })
      .catch((error) => {
        console.log(error);
 
      })  
 
  }

//this queries the specific users document and updates fields, the state is properly passed
  //the state is also a string
  fetchChanges = () => {
    console.log('i want to put this', this.state.profPic)
    console.log(typeof this.state.profPic)
    db.collection('users').doc(this.state.userID).set({
      'firstName': this.state.firstName,
      'lastName': this.state.lastName,
      'office': this.state.office,
      'bio': this.state.bio,
      'proPic': this.state.profPic
  })
    
    
  }

Hi all, been trying to workout this bug for hours and can't seem to be getting anywhere. Quick background, I'm running firebase version 4.10.0. The issue Im having here is that I'm using RN fetch blob and everything to store the blob into my firestorage and then pulling the download URL.

What i want to do next is store this download url in a specific users document for profile photos but the query or 'update' function wont go through when doing so. I've done multiple console logs and my data is being passed appropriately and I am pulling the url from storage. BUT when I want to update my 'proPic' field the entire query does not happen.

I've tested this by doing every other query without profile picture and it works perfect fine but when including profile picture and fetching the url etc the function does not do anything. I've tried setting the document as well as update and got no luck.

I can update all other fields but once my fetch blob is done and pulls the download URL, nothing will work.

UPDATE: I can also pass this state of profPic down to inputs and alerts but whenever i went to pass it in the field to write to the document, it still doesn't work. Perhaps I am querying my document wrong? I am so lost and don't know which direction to go.

eakrum avatar Mar 31 '18 05:03 eakrum

Hi all, hopefully this gets to the firebase team but theres a major issue right now regarding RNFetchblob and firestore. for some reason window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest is blocking calls to firestore upon calling. I'm using a temporary hacky solution right now but would be great to get a proper solution to this working eventually. We are targetting to use firestore in our app for production once beta is over so looking forward to a reply hopefully. Till then, I'll close the issue.

eakrum avatar Mar 31 '18 07:03 eakrum