是否可以使用react本机文档或下载保存文件?我正在尝试保存一个pdf文件,并使用react本机-fs:
let file = await RNHTMLtoPDF.convert(options)
const destinationPath = RNFS.DocumentDirectoryPath + "/" + fileName + ".pdf"
RNFS.copyFile(file.filePath, destinationPath)但是它保存在根目录(/data/user/0/com.prodhealth.mobile.Dev/files/TestTest_2022-02-22_2022-02-22.pdf)中,普通用户无法访问它。
有没有办法直接将其保存在手机内部存储的文档/下载中?我需要那个用户可以很容易地访问这个文件。
发布于 2022-02-23 09:38:57
您可以使用反应-本机-取-布
dirs这个常量是一个包含常用文件夹的散列映射:
示例
RNFetchBlob.fs.cp(SRC_PATH, DEST_PATH)
.then(() => { ... })
.catch(() => { ... })发布于 2022-11-23 15:02:10
可以,停那儿吧。对我来说很管用。
let file = await RNHTMLtoPDF.convert(options);
const destinationPath = RNFS.DownloadDirectoryPath;
const FileName = 'filename.pdf';
const destinationFile = destinationPath + "/" + FileName;
RNFS.copyFile(file.filePath, destinationFile)
.then(result => {
// Delete a file on the project path using RNFS.unlink
return RNFS.unlink(file.filePath)
.then(() => {
console.log('FILE DELETED');
})
// `unlink` will throw an error, if the item to unlink does not exist
.catch((err) => {
console.log(err.message);
});
})
.catch(err => {
console.log('err', err);
}); https://stackoverflow.com/questions/71229881
复制相似问题