我已经通过WhatsApp,Google等社交应用程序使用react-native-share npm来共享pdf文件,但这给了我错误“共享失败,请重试”。下面是示例代码:-
sharePress = async () => {
let filePath = null;
const configOptions = { fileCache: true };
this.setState({
spinner: true
}, () => {
RNFetchBlob.config(configOptions)
.fetch('GET', 'https://www.ets.org/Media/Tests/TOEFL/pdf/SampleQuestions.pdf') // pdf url
.then(resp => {
filePath = resp.path();
return resp.readFile('base64');
})
.then(base64Data => {
this.setState({
spinner: false
}, () => {
base64Data = `data:application/pdf;base64,` + base64Data;
Share.open({
url: base64Data,
}).then((res) => {
console.log('CORTEX: TKT_371: send(): res: ' + res)
})
.catch((err) => { console.log('CORTEX: TKT_373: send(): error for some reason: ' + err); });
});
})
})
}