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

If it calls continuously, an error occurs. #19

Closed ko2ic closed 5 years ago

ko2ic commented 5 years ago

This is a continuation of https://github.com/ko2ic/image_downloader/issues/14 .

@kraster010 wrote:

I've tried it only on Android.

Basically a server send me a set of images link which i then try to download. here the snippet. there are about 10 images in the framePath array.

for(var elem in video.framePaths){
    try{
        await ImageDownloader.downloadImage(api.getImageUrl(elem));
    } catch(_) {
        print("can't download image $elem");
    }
 }

The links are only available for 5 minutes so if you try to get the image now you will get a 404. but when the link is valid and i try to download the image this stacktrace happens: (maybe it downloads 4 out 10 images then it crashes, sometimes 1 out 10, sometimes 2 out 10. but everytime the app crashes)

This is the stacktrace: 10:49:27.589 105 info flutter.tools D/image_downloader( 3777): RequestResult(id=22, remoteUri=https://mobile.powerseriesneogo.com/mobile-api/rest/session/56f18efb-b228-4e52-bbb6-8df301ee85bf/video/file/1221018012_1554837934000_12_10_1.jpg, localUri=file:///storage/emulated/0/Download/2019-04-10.10.49.039, mediaType=image/jpeg, totalSize=3434, title=2019-04-10.10.49.039, description=) 10:49:27.589 106 info flutter.tools D/AndroidRuntime( 3777): Shutting down VM 10:49:27.606 107 info flutter.tools E/AndroidRuntime( 3777): FATAL EXCEPTION: main 10:49:27.606 108 info flutter.tools E/AndroidRuntime( 3777): Process: com.dsc.powerneo, PID: 3777 10:49:27.606 109 info flutter.tools E/AndroidRuntime( 3777): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=com.dsc.powerneo (has extras) } in com.ko2ic.imagedownloader.Downloader$execute$1@2a076ee 10:49:27.606 110 info flutter.tools E/AndroidRuntime( 3777): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1401) 10:49:27.606 111 info flutter.tools E/AndroidRuntime( 3777): at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2) 10:49:27.606 112 info flutter.tools E/AndroidRuntime( 3777): at android.os.Handler.handleCallback(Handler.java:873) 10:49:27.606 113 info flutter.tools E/AndroidRuntime( 3777): at android.os.Handler.dispatchMessage(Handler.java:99) 10:49:27.606 114 info flutter.tools E/AndroidRuntime( 3777): at android.os.Looper.loop(Looper.java:193) 10:49:27.606 115 info flutter.tools E/AndroidRuntime( 3777): at android.app.ActivityThread.main(ActivityThread.java:6669) 10:49:27.606 116 info flutter.tools E/AndroidRuntime( 3777): at java.lang.reflect.Method.invoke(Native Method) 10:49:27.606 117 info flutter.tools E/AndroidRuntime( 3777): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 10:49:27.606 118 info flutter.tools E/AndroidRuntime( 3777): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 10:49:27.606 119 info flutter.tools E/AndroidRuntime( 3777): Caused by: java.lang.IllegalStateException: newMimeType must not be null 10:49:27.606 120 info flutter.tools E/AndroidRuntime( 3777): at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:223) 10:49:27.606 121 info flutter.tools E/AndroidRuntime( 3777): at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:155) 10:49:27.606 122 info flutter.tools E/AndroidRuntime( 3777): at com.ko2ic.imagedownloader.Downloader.resolveDownloadStatus(Downloader.kt:125) 10:49:27.606 123 info flutter.tools E/AndroidRuntime( 3777): at com.ko2ic.imagedownloader.Downloader.access$resolveDownloadStatus(Downloader.kt:12) 10:49:27.606 124 info flutter.tools E/AndroidRuntime( 3777): at com.ko2ic.imagedownloader.Downloader$execute$1.onReceive(Downloader.kt:31) 10:49:27.606 125 info flutter.tools E/AndroidRuntime( 3777): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1391) 10:49:27.606 126 info flutter.tools E/AndroidRuntime( 3777): ... 8 more 10:49:27.606 127 info flutter.tools I/Process ( 3777): Sending signal. PID: 3777 SIG: 9

let me know if you need something more

kraster010 commented 5 years ago

submitted pull request #20.

ko2ic commented 5 years ago

20 #21 #22 is PR of fix to crash when MimeType cannot be determined.

It is not a fundamental solution to acquire multiple images.

ko2ic commented 5 years ago

@kraster010 v0.13.4 has been released.
Does this solve the problem?
I think that it happens that the image is not sometimes acquired.

kraster010 commented 5 years ago

@kraster010 v0.13.4 has been released. Does this solve the problem?

yes v0.13.4 solve the problem i was having from the code you posted on the first post. thanks

ko2ic commented 5 years ago

Release v0.14.1.

Please refer to the following.
https://github.com/ko2ic/image_downloader#downloading-multiple-files