itinance / react-native-fs

Native filesystem access for react-native
MIT License
4.94k stars 975 forks source link

Use react-native-fs download a mp4 file,is very slow #230

Open ghost opened 7 years ago

ghost commented 7 years ago

the mp4 is 698K but download it,is very slow,very very slow.

Do you have this question?

navsaini53 commented 7 years ago

same issue... an audio file of few mb takes minutes of time to download.

kaola8246 commented 7 years ago

me too.

airman00 commented 7 years ago

Are you running your app in Debug mode or Release?

navsaini53 commented 7 years ago

release

On Fri, Feb 17, 2017 at 8:32 PM, Eric Forkosh notifications@github.com wrote:

Are you running your app in Debug mode or Release?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/johanneslumpe/react-native-fs/issues/230#issuecomment-280673288, or mute the thread https://github.com/notifications/unsubscribe-auth/AHcOS50TfpAqsgqrdWqv6rCK4EGlW-c0ks5rdbadgaJpZM4LdS4T .

itinance commented 7 years ago

iOS or Android or both?

itinance commented 7 years ago

Under the hood this Lib uses native methods to manage network requests:

iOS: NSUrlSessionDownloadTask Android: HttpUrlConnection

But, on Android the Buffer-Size is very small (8 kb). You might want to increase the buffer-size for testing purposes and make a suggestion if you could speed up the download process then?

Change these both lines for testing with a higher buffer size (maybe 64 kb or more):

  1. https://github.com/itinance/react-native-fs/blob/master/android/src/main/java/com/rnfs/Downloader.java#L103
  2. https://github.com/itinance/react-native-fs/blob/master/android/src/main/java/com/rnfs/Downloader.java#L106

Don't forget to restart the packager after modification of native library code and to recompile/reinstall the app then. Let me know if you could speed it up pls.

marf commented 6 years ago

Hello @itinance, I have the same problem on iOS, how can I solve it?

Thank you, Marco

a812975315 commented 6 years ago

slow? you setState prograss?

sebqq commented 5 years ago

did anyone solve this?

schumannd commented 5 years ago

Same problem. rn-fetch-blob has (had, before parallel download broke) much better download performance.

bilal-korir commented 6 months ago

In my case changing the background property from false to true solved the speed issue.

const progress = RNFS.downloadFile({
background: false, // if true, download is going to be very slow on iOS.
begin: file => (contentLength = file.contentLength),
discretionary: true,
fromUrl: url,
progressDivider: 5,
toFile: localUrl,
progress: res => {
  let progress = (res.bytesWritten / res.contentLength) * 100
  progress = parseInt(progress?.toFixed(2))
  console.log(progress)
  }
})