Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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
React native 如何从本地存储中读取文件?_React Native - Fatal编程技术网

React native 如何从本地存储中读取文件?

React native 如何从本地存储中读取文件?,react-native,React Native,我正在将图像上传到设备的本地存储(Android),任务正在顺利完成 当我试图从本地存储读取文件时,会出现问题,它会弹出错误 说: 不变冲突对象不是有效的子对象 以下是我上传图像的代码: let dirs = RNFetchBlob.fs.dirs; RNFetchBlob.fs.exists(dirs.PictureDir + "/myfolder") .then((exist) => { //console.log(`file ${exist ? ''

我正在将图像上传到设备的本地存储(Android),任务正在顺利完成 当我试图从本地存储读取文件时,会出现问题,它会弹出错误 说:

不变冲突对象不是有效的子对象

以下是我上传图像的代码:

let dirs = RNFetchBlob.fs.dirs;
RNFetchBlob.fs.exists(dirs.PictureDir + "/myfolder")
    .then((exist) => {
            //console.log(`file ${exist ? '' : 'not'} exists`);
            if (!exist) {
                try {
                    const fs = RNFetchBlob.fs;
                    /
                    RNFetchBlob.fs.mkdir(dirs.PictureDir + "/myfolder")
                        .then(() => {
                                let base64Str = data;
                                fs.writeFile(dirs.PictureDir + "/myfolder/" + imageName, base64Str, 'base64')
                                    .then(() => {
                                        RNFetchBlob.fs.scanFile([{
                                            path: dirs.PictureDir + "/myfolder/",
                                            mime: 'jpeg/jpg'
                                        }]);
                                    }).catch(() => {
                                        alert("error");
                                    })
这是我的形象之路

常量路径= dirs.PictureDir+“/myfolder/1718179779c718ba84098b90f6061816fba9f.jpg”

这是我访问该图像的代码,你能帮忙吗

<ScrollView keyboardShouldPersistTaps="handled">

        <View style={styles.containerWithMargin} >
        {RNFetchBlob.fs.readFile(path, 'base64') .then( (data) =>
             <Avatar
             medium
             onPress={this.onSelectPostImage.bind(this)}
             source={{uri : data}}
           />
        )}

        </View>

{RNFetchBlob.fs.readFile(路径'base64')。然后((数据)=>
)}

RNFetchBlob.fs.readFile
返回一个承诺,任何异步的东西都应该在
ComponentDidMount
中,从那里你可以使用
setState
设置
imageUrl
,例如,在jsx中你会有这样的东西

<View style={styles.containerWithMargin} >
{imageUrl && 
   <Avatar
         medium
         onPress={this.onSelectPostImage.bind(this)}
         source={{uri : imageUrl}}
       />
}
</View

{imageUrl&&
}