ko2ic / image_downloader

Flutter plugin that downloads images and movies on the Internet and saves to Photo Library on iOS or specified directory on Android.
https://pub.dartlang.org/packages/image_downloader#-readme-tab-
MIT License
92 stars 116 forks source link

App crashes for large file #27

Closed mbenci closed 4 years ago

mbenci commented 5 years ago

My Android app crashes when I download large file. I have 2 videos: one of 16.6 MB and one of 18.3 MB Systematically when I try to download the larger the app crashes. No problems for the other video. The only way to solve the problem is setting inExternalFilesDir(). These are the logs:

/AndroidRuntime( 5865): Process: it.injenia.tools.interacta.mobile.dev, PID: 5865
E/AndroidRuntime( 5865): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=it.injenia.tools.interacta.mobile.dev (has extras) } in com.ko2ic.imagedownloader.Downloader$execute$1@66896a7
E/AndroidRuntime( 5865):    at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1533)
E/AndroidRuntime( 5865):    at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2)
E/AndroidRuntime( 5865):    at android.os.Handler.handleCallback(Handler.java:891)
E/AndroidRuntime( 5865):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 5865):    at android.os.Looper.loop(Looper.java:207)
E/AndroidRuntime( 5865):    at android.app.ActivityThread.main(ActivityThread.java:7539)
E/AndroidRuntime( 5865):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5865):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
E/AndroidRuntime( 5865):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
E/AndroidRuntime( 5865): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
E/AndroidRuntime( 5865):    at android.database.AbstractCursor.checkPosition(AbstractCursor.java:468)
E/AndroidRuntime( 5865):    at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
E/AndroidRuntime( 5865):    at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
E/AndroidRuntime( 5865):    at android.database.CursorWrapper.getString(CursorWrapper.java:137)
E/AndroidRuntime( 5865):    at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl.saveToDatabase(ImageDownloaderPlugin.kt:320)
E/AndroidRuntime( 5865):    at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl.access$saveToDatabase(ImageDownloaderPlugin.kt:194)
E/AndroidRuntime( 5865):    at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:274)
E/AndroidRuntime( 5865):    at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:194)
E/AndroidRuntime( 5865):    at com.ko2ic.imagedownloader.Downloader.resolveDownloadStatus(Downloader.kt:165)
E/AndroidRuntime( 5865):    at com.ko2ic.imagedownloader.Downloader.access$resolveDownloadStatus(Downloader.kt:12)
E/AndroidRuntime( 5865):    at com.ko2ic.imagedownloader.Downloader$execute$1.onReceive(Downloader.kt:31)
E/AndroidRuntime( 5865):    at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1520)
E/AndroidRuntime( 5865):    ... 8 more
rogiervandenberg commented 5 years ago

Thanks for this wonderful plugin, but I unfortunately have the same (Android only) issue:

E/AndroidRuntime( 2127): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=com.embrosa.photos (has extras) } in com.ko2ic.imagedownloader.Downloader$execute$1@3f9b1e9
E/AndroidRuntime( 2127):    at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1401)
E/AndroidRuntime( 2127):    at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2)
E/AndroidRuntime( 2127):    at android.os.Handler.handleCallback(Handler.java:873)
E/AndroidRuntime( 2127):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2127):    at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime( 2127):    at android.app.ActivityThread.main(ActivityThread.java:6718)
E/AndroidRuntime( 2127):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 2127):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime( 2127):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/AndroidRuntime( 2127): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
E/AndroidRuntime( 2127):    at android.database.AbstractCursor.checkPosition(AbstractCursor.java:468)
E/AndroidRuntime( 2127):    at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
E/AndroidRuntime( 2127):    at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
E/AndroidRuntime( 2127):    at android.database.CursorWrapper.getString(CursorWrapper.java:137)
E/AndroidRuntime( 2127):    at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl.saveToDatabase(ImageDownloaderPlugin.kt:320)
E/AndroidRuntime( 2127):    at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl.access$saveToDatabase(ImageDownloaderPlugin.kt:194)
E/AndroidRuntime( 2127):    at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:274)
E/AndroidRuntime( 2127):    at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:194)
E/AndroidRuntime( 2127):    at com.ko2ic.imagedownloader.Downloader.resolveDownloadStatus(Downloader.kt:165)
E/AndroidRuntime( 2127):    at com.ko2ic.imagedownloader.Downloader.access$resolveDownloadStatus(Downloader.kt:12)
E/AndroidRuntime( 2127):    at com.ko2ic.imagedownloader.Downloader$execute$1.onReceive(Downloader.kt:31)
E/AndroidRuntime( 2127):    at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1391)
ko2ic commented 5 years ago

@mbenci @rogiervandenberg

I want to solve this, but do not know how to reproduce. I tried with a 99.8M file, but it works without problems. Could you tell me a little more?

rogiervandenberg commented 4 years ago

It structurally crashes (also 0.19.0) on downloading images from uri's that do not provide the right headers. So, for instance I have an image file that returns application/x-msdownload as header 😔, while being an image. Even though my browser can show it correctly, it crashes the image_downloader plugin.

ko2ic commented 4 years ago

@rogiervandenberg Thank you for information. It will be transferred to the following isuue.

https://github.com/ko2ic/image_downloader/issues/54