Javascript Getting:TypeError:undefined不是将blob上载到firebase存储时的函数(计算';文件路径.replace(&';文件://&&';';';)';)

Javascript Getting:TypeError:undefined不是将blob上载到firebase存储时的函数(计算';文件路径.replace(&';文件://&&';';';)';),javascript,firebase,react-native,firebase-storage,react-native-firebase,Javascript,Firebase,React Native,Firebase Storage,React Native Firebase,我正在开发一个带有firebase存储的小型React本机POC,用户在其中选择图像并将其上载到firebase存储的/uid/目录下。 我正在使用react native firebase在应用程序中使用firebase 我有图像的uri,我正在使用RNFetchBlob创建它的blob,然后尝试将blob上传到firebase 下面是处理blob生成和上传的代码 handleUploadTask = (mime = 'application/octet-stream') => {

我正在开发一个带有firebase存储的小型React本机POC,用户在其中选择图像并将其上载到firebase存储的
/uid/
目录下。 我正在使用
react native firebase
在应用程序中使用firebase

我有图像的
uri
,我正在使用
RNFetchBlob
创建它的blob,然后尝试将blob上传到firebase

下面是处理blob生成和上传的代码

handleUploadTask = (mime = 'application/octet-stream') => {
    const {imageSource} = this.state;
    this.setState({uploading: true});

    const Blob = RNFetchBlob.polyfill.Blob;
    const fs = RNFetchBlob.fs;

    fs.readFile(imageSource.uri, 'base64')
        .then((data) => {
            return Blob.build(data, { type: `${mime};BASE64` })
        }).then(blob => {
            console.log('going to upload');
            this.uploadBlobToFirebase(blob);
        }).catch(error => {
            console.error('fs error:', error);
        })
}
这是
上传blobtofirebase

uploadBlobToFirebase = (blob) => {
    const currentUserId = firebase.auth().currentUser.uid;
    const path = `/${currentUserId}/`;
    const unsubscribe = firebase.storage().ref(path).putFile(blob).on(
        firebase.storage.TaskEvent.STATE_CHANGED,
        (snapshot) => {
        const  progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
        //restricting progress to be shown with only 0,2,4,... 98, 100.
        if (progress % 2 == 0) {
            this.setState({
                uploadProgress: progress
            })
        }

        if (snapshot.state === firebase.storage.TaskState.SUCCESS) {
            this.setState({
                uploading: false,
            }, () => {
                //TODO: should also add this image to flatlist.
                //Get download url and set to image in flatlist.
                Alert.alert('Upload completed');
            })

          }
        },
        (error) => {
            this.setState({
                uploading: false,
            }, ()=>{
                unsubscribe();
                console.error(error);
            })
        },
      ); 
}
按下上载按钮调用函数
handleUploadTask
,直到
console.log('going to upload')
正常运行,然后进入错误捕获:

'fs error:',{[TypeError:undefined不是函数(计算'filePath.replace('file://','')] 电话:115903, 栏目:41, 源URL:'}

我这里一片空白。找不到
文件。请替换导致问题的
,并说明原因。
任何帮助都将不胜感激。谢谢。

putFile
需要位于本机存储上的文件的字符串路径

您需要将blob保存到设备上临时存储器中的文件中,然后将该临时文件的路径提供给
putFile
方法

React Native Firebase确实提供了一些静态信息,可以帮助定位设备上的某些目录,例如,通过
Firebase.storage.Native.temporary\u directory\u PATH
定位临时目录。有关这些文档,请参见

它的设计是这样的,因为通过React-Native桥接器传输文件/blob与保持所有内容的本地性相比,将是一个巨大的性能打击

根据示例代码,您应该能够执行以下操作:

firebase.storage().ref(path).putFile(imageSource.uri).on(/* ... */);
putFile示例参考文件位于以下位置: