joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.8k stars 770 forks source link

Crash when downloading large file, even when downloading directly to file #24

Open laurent22 opened 6 years ago

laurent22 commented 6 years ago

Not sure if this is a bug or if I'm doing something wrong but I'm getting the following crash when downloading a large file (96MB)

04-30 12:00:18.972 13006 13059 E AndroidRuntime: FATAL EXCEPTION: pool-1-thread-1
04-30 12:00:18.972 13006 13059 E AndroidRuntime: Process: net.cozic.joplin, PID: 13006
04-30 12:00:18.972 13006 13059 E AndroidRuntime: java.lang.OutOfMemoryError: Failed to allocate a 257944612 byte allocation with 4190304 free bytes and 160MB until OOM
04-30 12:00:18.972 13006 13059 E AndroidRuntime:        at java.lang.StringFactory.newStringFromBytes(StringFactory.java:185)
04-30 12:00:18.972 13006 13059 E AndroidRuntime:        at java.lang.StringFactory.newStringFromBytes(StringFactory.java:63)
04-30 12:00:18.972 13006 13059 E AndroidRuntime:        at android.util.Base64.encodeToString(Base64.java:456)
04-30 12:00:18.972 13006 13059 E AndroidRuntime:        at com.RNFetchBlob.RNFetchBlobFS.readFile(RNFetchBlobFS.java:174)
04-30 12:00:18.972 13006 13059 E AndroidRuntime:        at com.RNFetchBlob.RNFetchBlob$6.run(RNFetchBlob.java:208)
04-30 12:00:18.972 13006 13059 E AndroidRuntime:        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
04-30 12:00:18.972 13006 13059 E AndroidRuntime:        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
04-30 12:00:18.972 13006 13059 E AndroidRuntime:        at java.lang.Thread.run(Thread.java:761)
04-30 12:00:18.975  1705  3755 W ActivityManager:   Force finishing activity net.cozic.joplin/.MainActivity

It seems to crash on Base64 decoding which appears to be expected, however I'm setting the config so that it downloads directly to a file, so my understanding is that base64 decoding should not happen:

return RNFetchBlob.config({
    path: localFilePath
}).fetch(method, url, headers);

Any idea what am I might be doing wrong or how to avoid this crash?

I'm using fetch-blob 0.10.6 and RN 0.49.

laurent22 commented 6 years ago

I have also tried using the fileCache: true property. In this case it does not crash, however when I try to move the file to its final location I get the error:

/data/user/0/net.cozic.joplin/files/RNFetchBlobTmp_9nirk2hsaglipqaokxych (No such file or directory)

If I go to this directory using adb shell it says "permission denied" as I'm not root but I assume the file has been created, except it somehow cannot be accessed.

Any suggestion on how to solve this? Basically what is the correct way to download a large file to a specific location?

ihusak commented 5 years ago

the same issue...

fukemy commented 1 year ago

same problem here

NandoMB commented 1 year ago

Same here

yanghun0070 commented 5 months ago

Same problem

Di4ik3r commented 4 months ago

Same problem