artem-zinnatullin / jet-image-loader

WP7+ fast and powerfull image loader with memory and storage caching for your projects!
Apache License 2.0
44 stars 14 forks source link

Image does not finish downloading #32

Open mjfara opened 10 years ago

mjfara commented 10 years ago

Sometimes when there is limited connectivity, an image will not finish downloading and it will cache as an incomplete image. Most of the time it will show half of the image, and the rest of the image will be gray. How can I fix this issue?

artem-zinnatullin commented 10 years ago

Hmmmm, that's bad. I think, that problem is in HttpWebRequestDownloader.cs, I'll be happy if you can check it's sources https://github.com/artem-zinnatullin/jet-image-loader/blob/master/JetImageLoader/Network/HttpWebRequestDownloader.cs or you can try to write your own downloader — simply implement IDownloader and then use it in JetImageLoaderConfig

mjfara commented 10 years ago

Thank you for your response. I added your package through nuget. Do I have to do it differently in order to modify the source code? I am unfamiliar with how this all works.

artem-zinnatullin commented 10 years ago

No problem, just write your own implementation of IDownloader and pass it to the JetImageLoader from GetJetImageLoaderConfig, I recommend to firstly copy HttpWebRequestDownloader code and debug what's happening on bad internet connection

mjfara commented 10 years ago

Ah got it, will do, thanks! If I get a fix I will post it here.

artem-zinnatullin commented 10 years ago

Thank you :)

mjfara commented 10 years ago

Unfortunately this is difficult to diagnose as it happens when connection is dropped in the middle of a download. I was thinking of just putting a button in settings that will "Clear Cache". How can I do this?

cdbkr commented 10 years ago

I got an idea: I created a new property ContentLength in DownloadResult.cs . When creating a new DownloadResult in HttpWebRequestDownloader, I assign the response header "ContentLenght" to the new property created. In JetImageLoader we check if the resultstream content length is different from the contentlength header...

if (downloadResult.Exception != null || downloadResult.ResultStream == null || downloadResult.ResultStream.Length != downloadResult.ContentLength) { Log("[error] failed to download: " + imageUrl); return null; }

I just wrote this solution so Im going to debug it properly.