使用readFile()通过“ react-native-fetch-blob”或“ react-native-fs”读取“ react-native-view-shot”的tmpfile时出错

时间:2018-07-06 15:26:01

标签: react-native react-native-fetch-blob react-native-fs

“ react-native-fs”和“ rn-fetch-blob”的

readFile()方法对于静态资产文件或“ react-native-camera”库的输出均适用。

但是readFile()方法无法将通过“ react-native-view-shot”捕获的文件读取为tmpfile。

react-native@0.52.2
react-native-view-shot@2.3.0
react-native-fetch-blob@0.10.8 || rn-fetch-blob@0.10.11
react-native-fs@2.10.14

class SomeComponent extends Component {
  async captureAndReadFile() {
    try {
      let filePath = await this.viewShot.capture() ;
      let data = await RNFS.readFile(filePath, 'base64');  // or RNFetchBlob.fs.readFile(filePath, 'base64');
      return data && new Buffer.from(data, 'base64'); 
    }
    catch(err) {
      console.warn(err);
    }
  }

  render() {
    return(
      <View>
        <ViewShot 
          ref={ref => this.viewShot = ref}
          options={{ format: 'jpg', quality: 0.8 }}
        />
        <Button title="Press" onPress={this.captureAndReadFile.bind(this)}
      </View>
    );
  }

我想念什么吗?
预先感谢。

0 个答案:

没有答案