0

I appreciate any assistance that the community can offer! I have a React-native class component with the getPathForFirebaseStorage method that is called by a different method. However whenever the below method is called it returns :

{"_U": 0, "_V": 0, "_W": null, "_X": null}

where as the console.log from getPathForFirebaseStorage returns the actual local device path as is needed:

/storage/emulated/0/DCIM/Camera/IMG_20200726_091113.jpg

So any ideas on how I can improve getPathForFirebaseStorage so the return becomes accessible outside of its own local scope?? Here's the method:

getPathForFirebaseStorage = async (uri) => {
        const stat = await RNFetchBlob.fs.stat(uri)
        console.log(stat.path)
        return stat.path
    }

Here's the method where getPathForFirebaseStorage is being called:

handleLibraryPhoto = () => {
        const options = {
            storageOptions:  {
                path: 'images',
            }
        }
        ImagePicker.launchImageLibrary(options, (response) => {
            if (response.didCancel) {
                console.log('User cancelled image picker')
            } else if (response.error) {
                console.log('ImagePicker Error: ', response.error)
            } else if (response.customButton) {
                console.log('User tapped custom button: ', response.customButton)
            } else {
                const source = {uri: response.uri};
                const androidPath = this.getPathForFirebaseStorage(source.uri);
                this.setState({image: androidPath});
                console.log(this.state.image);
            }
        })
    }
  • Seems like it's returning a Promise. When you call the function do you use await? – Tamás Sallai Sep 11 '20 at 10:30
  • @TamásSallai Thanks for your response, i have tried to use await, but perhaps not correctly. Might you have a suggestion on how to call the function? If so would you provide a code sample? – Kol Ratner Sep 11 '20 at 10:46
  • Just put await before it :) Something like ```console.log(await getPathForFirabaseStorage(url))``` and see what it prints – Tamás Sallai Sep 11 '20 at 10:52
  • @TamásSallai I added the method where it is being called above...Im not sure how to structure it as an async method, i cant put await where getPathForFirebaseStorage is actually being called without the entire method being async – Kol Ratner Sep 11 '20 at 11:39
  • Your function is async, so handleLibraryPhoto has to be async too, then you just put an await before getPath... Now if you're calling this at render method you will need to use an effect hook – geckos Sep 11 '20 at 12:14

0 Answers0