Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何解决;“文件名太长”;在React Native中将本地映像上载到Firestore和Firebase存储时?_Javascript_Reactjs_React Native_Google Cloud Firestore_Firebase Storage - Fatal编程技术网

Javascript 如何解决;“文件名太长”;在React Native中将本地映像上载到Firestore和Firebase存储时?

Javascript 如何解决;“文件名太长”;在React Native中将本地映像上载到Firestore和Firebase存储时?,javascript,reactjs,react-native,google-cloud-firestore,firebase-storage,Javascript,Reactjs,React Native,Google Cloud Firestore,Firebase Storage,我正在尝试将本地图像上载到云Firestore和Firebase存储 我使用的包是 从本地选择图像的步骤 将文件作为blob传输到Firebase存储 以下是我正在使用的两个函数: export const uploadPost = async (postImageUri) => { return new Promise(async(res, rej) => { const fs = RNFetchBlob.fs;

我正在尝试将本地图像上载到云Firestore和Firebase存储

我使用的包是

  • 从本地选择图像的步骤
  • 将文件作为blob传输到Firebase存储
以下是我正在使用的两个函数:

export const uploadPost = async (postImageUri) => {

        return new Promise(async(res, rej) => {

                const fs = RNFetchBlob.fs;
                
                fs.readFile(postImageUri,'hello','base64')
                .then(async (data) => {
                    console.log('data from RNFetchBlob', data);
                    const storageRef = storage().ref(`posts/images`).child(`${data}`);
                    
                    try {
                        storageRef.putFile(data,{contentType: 'image/jpeg'})
                        .on(
                            storage.TaskEvent.STATE_CHANGED,
                            snapshot => {
                                console.log('snapshot', snapshot.state);
                                console.log('progress', (snapshot.bytesTransferred)/(snapshot.totalBytes)*100);

                                if(snapshot.state === storage.TaskState.SUCCESS){
                                    console.log('SUCCESS')
                                }
                            },
                            error => {
                                console.log('Image upload error', error);
                                rej(error)
                            },
                            () => {
                                storageRef.getDownloadURL()
                                .then((downLoadUri) => {
                                    console.log('File available at: ', downLoadUri);
                                    // addPostInfo
                                    res(downLoadUri)
                                })
                            }
                        )
                    }catch{err => console.log(err) }
                })

                
        } )
}

export const addPostInfo = async (post) => {
    
    console.log('post.postImageUri in addPostInfo', post.postImageUri.slice(10))
    const remoteUri = await uploadPost(post.postImageUri);
    return new Promise((res, rej) => {
        firestore()
        .collection('posts')
        .add({
            id: post.id,
            createdAt: post.date,
            description: post.description,
            image: remoteUri,
            location: post.checkin_location
        })
        .then(ref => {
            console.log('Finish adding in addPostInfo', ref)
            res(ref)
        })
        .catch(err => rej(err))
    })
}
在主屏幕中,我直接将
图像的路径发送到
addPostInfo

const _onSharingPost = () => {
        const postCreated = {
            id: 'alkdgjhfa;oiughaoghus',
            postImageUri: postImageUri,
            date: _getCurrentDate(),
            description: postDescription,
            checkin_location: checkInLocation
        }
        
        postActions.addPostInfo(postCreated);
    }
路径
如下所示:

content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F58/ORIGINAL/NONE/image%2Fjpeg/950379202
错误

...base64 string --> File name too long
它涉及到
upLoadPost
函数的
SUCCESS
部分,但仍然出现了错误

我已经试过了:

  • 更改路径-->切断
    内容://
  • 使用XMLHttpRequest将blob发送到
    upLoadPost
    以将其发送到存储器
据我所知,问题一定是从映像路径转换的
base64
字符串。我知道我们需要把它改成水滴什么的,但我不知道怎么做。我在
rn fetch blob
docs中找不到可以指定的位置

请帮帮我