RNFS.downloadFile not working on Android
I am having an issue where RNFS.downloadFIle will not work on Android, no crash or error, the app reaches this line RNFS.downloadFile(options).promise.then(response => { and never enters the block, not sure whats going on since no error message and this works fine on iOS.
Oddly this seems to work on some android emulators but not my devices i've tested such as galaxy s7 or s8.
react-native-fs 2.11.15
This is my full code block:
const fromPath = url const toPath = ${RNFS.DocumentDirectoryPath}/${tempArray[i].Image} const options = { fromUrl: fromPath, toFile: toPath, background: true, progressDivider: 10, } RNFS.exists(toPath).then(response => { if (!response) { RNFS.downloadFile(options).promise.then(response => { if (response.statusCode !== 200) { if (failedDownloads.indexOf(tempArray[i].Image) <= -1) { failedDownloads.push(tempArray[i].Image) } throw response } }).catch(err => err) } })
Check if has something to do with the permissions. For some reason something that was working before start failing these days, and asking for permissions for external storage fixed it.
Had the same issues. https://facebook.github.io/react-native/docs/permissionsandroid solved the problem. Just add permission for WRITE_EXTERNAL_STORAGE
Is this solved? I added permissions to manifest, but it doesn't work. I caught an error and it said:
ENOENT: no such file or directory, open '/data/user/0/com.someappname/files'
Any solution i am facing same isssue in android
I got the same error on Android.
i moved to document viewer
I was facing the same error, but, after implement the Android Permissions (WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE) and set the directory to ExternalDirectoryPath, I could solve the problem!
It works normally, maybe you forget to add RNFS.DocumentDirectoryPath?
const destPath = RNFS.DocumentDirectoryPath + '/app.zip'; const {id, promise} = RNFS.downloadFile({ fromUrl: config.databaseUrl, toFile: destPath, background: false, cacheable: false, connectionTimeout: 60 * 1000, readTimeout: 120 * 1000 });
meaning it can not work outside document directory path?
It works normally, maybe you forget to add RNFS.DocumentDirectoryPath?
const destPath = RNFS.DocumentDirectoryPath + '/app.zip'; const {id, promise} = RNFS.downloadFile({ fromUrl: config.databaseUrl, toFile: destPath, background: false, cacheable: false, connectionTimeout: 60 * 1000, readTimeout: 120 * 1000 });
Dammit! I'll have you know I have excellent logging. Too bad my nut for brains wasn't able to catch it. RNFS.DocumentsDirectoryPath was missing. Thanks for mentioning this. Sometimes the simplest of solutions is all you need
I was facing the same error, but, after implement the Android Permissions (WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE) and set the directory to ExternalDirectoryPath, I could solve the problem!
Hi @steniowagner , Did you update the permissions in AndroidManifest.xml file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
I have added below permission in android/app/src/main/AndroidManifest.xml :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
but it works fine in debug mode and not in release mode , any idea what could be causing this.
await RNFS.downloadFile({
fromUrl: uri,
toFile: `${RNFS.DocumentDirectoryPath}/img.png`,
}).promise;