是否可以在 Documents 或 Downloads 中使用 react-native 保存檔案?我正在嘗試使用 react-native-fs 保存 pdf 檔案:
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 )中。
有沒有辦法直接保存在手機內部存盤的檔案/下載中?我需要該用戶可以輕松訪問此檔案。
uj5u.com熱心網友回復:
你可以使用react-native-fetch-blob
- cp(src:string, dest:string):承諾
dirs這個常量是一個包含常用檔案夾的哈希映射:
- 檔案目錄
- MainBundleDir(僅可用于訪問嵌入在 iOS 應用程式中的檔案)
- 下載目錄(僅限 Android)
例子
RNFetchBlob.fs.cp(SRC_PATH, DEST_PATH)
.then(() => { ... })
.catch(() => { ... })
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/434794.html
