rn-fetch-blob icon indicating copy to clipboard operation
rn-fetch-blob copied to clipboard

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

Open laurent22 opened this issue 6 years ago • 6 comments

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 avatar Apr 30 '18 12:04 laurent22

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?

laurent22 avatar Apr 30 '18 12:04 laurent22

the same issue...

ihusak avatar Nov 07 '18 08:11 ihusak

same problem here

fukemy avatar Sep 14 '22 15:09 fukemy

Same here

NandoMB avatar Oct 07 '22 11:10 NandoMB

Same problem

yanghun0070 avatar Dec 09 '23 11:12 yanghun0070

Same problem

Di4ik3r avatar Jan 15 '24 15:01 Di4ik3r