我使用react-native-share
包裹
https://www.npmjs.com/package/react-native-share
我尝试以这种方式共享base64:
import Share from 'react-native-share'
//
const base64File = //base64 file
const pdf = "data:application/pdf;base64," + base64File
const options = { title: 'Share via', url: pdf };
Share.open(options)
它在android
中有效,但在IOS
中无效,当我尝试共享tiff
文件时,它在IOS
中有效,但在pdf
中无效
当我尝试此操作时会通知我-无法共享此文件
答案 0 :(得分:0)
我在响应本机共享时遇到类似的问题。然后,我使用react-native-share共享我的pdf文件
Share.open({
title: "Pdf file",
message: "my Text:",
url: "file:///storage/../../test.pdf",
subject: "PDF",
})
希望这对您有帮助
答案 1 :(得分:0)
解决方案
import Share from 'react-native-share'
import RNFetchBlob from 'rn-fetch-blob'
//
const base64File = //base64 file
const pdf = "data:application/pdf;base64," + base64File
let filePath = '';
const path = RNFetchBlob.fs.dirs.DocumentDir + '/someFileName.pdf';
const configOptions = { fileCache: true, path };
let fullPath = await RNFetchBlob.config(configOptions).fetch('GET', encodeURI(fileUrl))
filePath = fullPath.path();
let options = {
title: 'Share via'
type: type,
url: filePath // (Platform.OS === 'android' ? 'file://' + filePath)
};
Share.open(options)