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>
);
}
我想念什么吗?
预先感谢。