Last active
December 31, 2019 19:16
-
-
Save lydonchandra/931f407f2b9629edd9f5bd2c18057e5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
// get a list of files and directories in the main bundle | |
RNFS.readDir(NativeModules.RNFetchBlob.DownloadDir) // On Android, use "RNFS.DocumentDirectoryPath" (MainBundlePath is not defined) | |
.then((result) => { | |
console.log('GOT RESULT', result); | |
var promises = [] | |
result.forEach(async (path) => { | |
console.log("path", path) | |
promises.push(RNFS.copyFile(path.path, RNFS.DocumentDirectoryPath + "/" + path.name)) | |
}) | |
return promises | |
// stat the first file | |
// return Promise.all([ | |
// RNFS.stat(result[0].path), | |
// result[0].path]); | |
}) | |
.then((statResult) => { | |
console.log("=== statResult", statResult) | |
if (statResult[0].isFile()) { | |
// if we have a file, read it | |
return RNFS.readFile(statResult[1], 'base64'); | |
} | |
console.log("--- no file") | |
return 'no file'; | |
}) | |
.then((contents) => { | |
// log the file contents | |
//console.log('logging contents', contents); | |
}) | |
.catch((err) => { | |
console.log('error', err.message, err.code); | |
}); | |
} catch (err) { | |
console.log("--------err ", err) | |
if (DocumentPicker.isCancel(err)) { | |
// User cancelled the picker, exit any dialogs or menus and move on | |
} else { | |
throw err; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment