react-native-fs笔记
1.RNFS常用路径:
MainBundlePath: RNFSManager.RNFSMainBundlePath,
CachesDirectoryPath: RNFSManager.RNFSCachesDirectoryPath,
DocumentDirectoryPath: RNFSManager.RNFSDocumentDirectoryPath,
ExternalDirectoryPath: RNFSManager.RNFSExternalDirectoryPath,
ExternalStorageDirectoryPath: RNFSManager.RNFSExternalStorageDirectoryPath,
TemporaryDirectoryPath: RNFSManager.RNFSTemporaryDirectoryPath,
LibraryDirectoryPath: RNFSManager.RNFSLibraryDirectoryPath,
PicturesDirectoryPath: RNFSManager.RNFSPicturesDirectoryPath
对应iOS下路径示例:
"/Users/gaojie/Library/Developer/CoreSimulator/Devices/7A7897A7-7A1E-4D3B-8B43-9DFD99438B18/data/Containers/Data/Application/65FB693B-483C-4582-99AA-2B27FEB76530/Library/Caches",
"/Users/gaojie/Library/Developer/CoreSimulator/Devices/7A7897A7-7A1E-4D3B-8B43-9DFD99438B18/data/Containers/Data/Application/65FB693B-483C-4582-99AA-2B27FEB76530/Documents",
null,
null,
"/Users/gaojie/Library/Developer/CoreSimulator/Devices/7A7897A7-7A1E-4D3B-8B43-9DFD99438B18/data/Containers/Data/Application/65FB693B-483C-4582-99AA-2B27FEB76530/tmp/",
"/Users/gaojie/Library/Developer/CoreSimulator/Devices/7A7897A7-7A1E-4D3B-8B43-9DFD99438B18/data/Containers/Data/Application/65FB693B-483C-4582-99AA-2B27FEB76530/Library",
null
使用举例(安卓)
let imgName = uuidOutLine+'.png';
let dirPath = this.config.deliveryCheckHousePath;
let imgPath = dirPath+'/'+imgName;
//1.检查目标文件夹是否存在
RNFS.exists(dirPath).then((result) => {
this.log('exist:'+result);
if (result) {
//3.图片迁移
RNFS.copyFile(uri, imgPath).then((result) => {
console.log(dirPath)
console.log('copyFile:'+result);
})
} else {
//2.新建文件夹
RNFS.mkdir(dirPath).then((result)=>{
this.log('mkdir:'+result);
//3.图片迁移
RNFS.copyFile(uri, imgPath).then((result) => {
console.log('copyFile:'+result)
})
})
}
})
网友评论