react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

RNFS.downloadFile not working on Android

Open beisert1 opened this issue 7 years ago • 12 comments

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) } })

beisert1 avatar Sep 14 '18 19:09 beisert1

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.

gaguirre avatar Sep 20 '18 15:09 gaguirre

Had the same issues. https://facebook.github.io/react-native/docs/permissionsandroid solved the problem. Just add permission for WRITE_EXTERNAL_STORAGE

illiteratewriter avatar Oct 18 '18 13:10 illiteratewriter

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'

Rendfold avatar Dec 13 '18 10:12 Rendfold

Any solution i am facing same isssue in android

zhdishaq avatar Jan 20 '19 08:01 zhdishaq

I got the same error on Android.

onitzschke avatar Feb 10 '19 02:02 onitzschke

i moved to document viewer

zhdishaq avatar Feb 10 '19 06:02 zhdishaq

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!

steniowagner avatar Feb 14 '19 01:02 steniowagner

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
});

anhhh11 avatar Apr 30 '19 04:04 anhhh11

meaning it can not work outside document directory path?

lylest avatar May 24 '20 10:05 lylest

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

Selman555 avatar Oct 24 '20 13:10 Selman555

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" />

bhupendra1011 avatar Dec 26 '23 08:12 bhupendra1011

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;

bhupendra1011 avatar Jan 02 '24 11:01 bhupendra1011