Rn-fetch-blob: Crash when downloading large file, even when downloading directly to file

Created on 30 Apr 2018  路  2Comments  路  Source: joltup/rn-fetch-blob

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.

Most helpful comment

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?

All 2 comments

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?

the same issue...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

viv3kk picture viv3kk  路  13Comments

wamry picture wamry  路  16Comments

fgagneten picture fgagneten  路  23Comments

fa16mscs0004 picture fa16mscs0004  路  13Comments

Evangelione picture Evangelione  路  16Comments