简书参考:https://www.jianshu.com/p/6f3f36f404d2
注意
let dirs = Platform.OS === 'ios' ? RNFS.LibraryDirectoryPath : RNFS.ExternalDirectoryPath; //外部文件,共享目录的绝对路径(仅限android)
const downloadDest = `${dirs}/${((Math.random() * 10000000) | 0)}.jpg`;
此处用于区分ios和安卓
另附RNFS导出中提供的常量:
MainBundlePath(String)主包目录的绝对路径(Android上不可用)
CachesDirectoryPath(String)高速缓存目录的绝对路径
DocumentDirectoryPath (String)文档目录的绝对路径
TemporaryDirectoryPath(String)临时目录的绝对路径(回到Android上的Caching-Directory)
LibraryDirectoryPath(String)NSLibraryDirectory的绝对路径(仅适用于iOS)
ExternalDirectoryPath(String)外部文件,共享目录的绝对路径(仅限android)
ExternalStorageDirectoryPath(String)外部存储的绝对路径,共享目录(仅限android)
demo:https://github.com/SCJMENGMENG/StorageImgUseReactNative.git
react-native-fetch-blob demo:
https://github.com/SCJMENGMENG/downloadTest.git