例如,当我通过whatsapp在ANDROID上共享PDF文件时,例如在android上,该文件会带有一个偶然的名称,例如(81276392183)。
为此,我使用以下lib:“ react-native-fetch-blob”;
[信息] “ reactive-native”:“ 0.59”, “ react-native-fetch-blob”:“ ^ 0.10.8”,
这是我要分享的功能: 从“ react-native-fetch-blob”导入RNFetchBlob;
shareCard = async card => {
console.log({ CARD: card });
const { url_pdf, nome } = card;
const formattedName = nome.trim();
const DIRS = RNFetchBlob.fs.dirs;
if (Platform.OS === "android") {
const path = `${DIRS.DocumentDir}/folder/${formattedName}.pdf`;
RNFetchBlob.config({
// add this option that makes response data to be stored as a file,
// this is much more performant.
fileCache: true,
path
})
.fetch("GET", url_pdf)
.then(resp => resp.readFile("base64"))
.then(async base64Data => {
const base64DataToShare = `data:application/pdf;base64,${base64Data}`;
await Share.open({
// title: "Compatilhar PDF",
url: base64DataToShare
// type: "base64",
// filename: "test",
});
});
} else {
let filePath = null;
const configOptions = {
fileCache: true,
path: `${DIRS.DocumentDir}/${formattedName}.pdf`
};
RNFetchBlob.config(configOptions)
.fetch("GET", url_pdf)
.then(async resp => {
filePath = resp.path();
const options = {
type: "application/pdf",
url: filePath
};
await Share.open(options);
});
}
};
我的目标是使用户可以在下载之前查看文件名:)
我想知道是否可以使用此lib或其他名称将该名称放入android中的文件中。