itinance / react-native-fs

Native filesystem access for react-native
MIT License
4.96k stars 985 forks source link

Android downloadFile completely freezes the app #443

Open mdrbohlav opened 6 years ago

mdrbohlav commented 6 years ago

When I start downloading large file the app completely freezes.

My config is really simple:

const config = {
  fromUrl: url,
  toFile: path,
  progressDivider: 1,
  begin: ({ contentLength }) => {
    processProgress(contentLength);
  },
  progress: ({ contentLength, bytesWritten }) => {
    processProgress(contentLength, bytesWritten);
  },
};

const task = RNFS.downloadFile(config);

Android: 6.0 and 7.1.1, both emulated with remote debugging on RN: 0.51.0 RNFS: 2.9.10

itinance commented 6 years ago

At zizzle we use this function to download large files and even show a progressbar at the bottom of the screen, while the user can navigate between different views without and freeze.

Seems that something different is causing your issue.

mdrbohlav commented 6 years ago

There is nothing else happening in the moment of the download. But I found for some reason on Android the file size of a specific file is not known (did not check if the header 'content-length' is set but it works fine on iOS) which means the progressDivider has no effect and it sends progress notification each few ms.

Kendysond commented 5 years ago

For me, removing my download progress function resolved the freeze on Android. I guess it's because redux keeps updating the state at each progress increment. Sad that android users can't see an actual progress view, but I guess it's cool.

sergibel commented 5 years ago

Option progressDivider do not work if the server does not provide response content length. To reduce the frequency of callbacks, the option progressInterval defines how often the progress is returned, see PR #717