imgcache.js icon indicating copy to clipboard operation
imgcache.js copied to clipboard

Images are corrupted cordova?

Open MoatazAbdallh opened this issue 11 years ago • 9 comments

Hello we are using ImgCache in App but some images appears corrupted,So is there any solution for this issue. Regards

screenshot_2014-12-22-14-35-35 screenshot_2014-12-22-14-12-46

here's our code:

useCachedFile: function (url, baseUrl) { ImgCache.isCached( baseUrl + url, function (path, success) { var img = $("[img-src='" + path + "']"); if (success) { // already cached console.log("used from cache"); ImgCache.getCachedFileURL(path, function (img_src, file_url) { console.log("found in cache"); $(img).attr('src', file_url); }) } else { // not there, need to cache the image $(img).attr('src', '/vendors/imageCache/placeholder.png'); ImgCache.cacheFile(baseUrl + url, function () { ImgCache.getCachedFileURL(baseUrl + url, function (img_src, file_url) { console.log("found in cache"); $(img).attr('src', file_url); }) }, function () { $(img).attr('src', baseUrl + url); }); } }); }

MoatazAbdallh avatar Dec 22 '14 12:12 MoatazAbdallh

I guess this is the problem described in issue #76 : did you close the application / stop the cacheFile before it has time to download the files correctly?

chrisben avatar Dec 22 '14 12:12 chrisben

no, you could see from the previous code that after we cache files we used the cached version, also due to compatibility we use cordova v2.9

MoatazAbdallh avatar Dec 22 '14 13:12 MoatazAbdallh

What is the mobile operating system you're targeting?

chrisben avatar Dec 22 '14 13:12 chrisben

Android version

MoatazAbdallh avatar Dec 22 '14 13:12 MoatazAbdallh

A similar issue with Android: #84 . Can you target another OS to test? As reported in this issue, several problems with the file plugin for Android. Could you perhaps use a newer version of the file plugin while keeping your older cordova version?

chrisben avatar Dec 22 '14 13:12 chrisben

Hello,

I have the same problem but this time on IOS, when the cache is empty and there are a lot of images which should be downloaded, cached and then displayed. Some of the images appear only partially.

ImgCache.isCached(url, function(path, success){ if(success){ console.log('util.js:preloadImage:Image ' + url + ' is cached. target: ' + target(imgId)); ImgCache.useCachedFileWithSource(target(imgId), url, function(){ if (aSize==1){imageResize(target(imgId), 64, 64);} } ); } else { console.log('util.js:preloadImage:Image ' + url + ' is NOT CACHED. target: ' + target(imgId)); ImgCache.cacheFile(url, function(){ ImgCache.useCachedFileWithSource(target(imgId), url, function(){ if (aSize==1){imageResize(target(imgId), 64, 64);} } ); }); } });

alexandrubarbat avatar Dec 23 '14 02:12 alexandrubarbat

Thanks chrisben for your reply, for this issue its recommended to use the online version of the images at first time to avoid corruption. so in else case use to online version else { ImgCache.cacheFile(baseUrl + url, function () { $(img).attr('src', baseUrl + url); } another question is imageCaching working in WP 8

MoatazAbdallh avatar Dec 23 '14 09:12 MoatazAbdallh

Indeed there should be no need to directly use the cached version of the files as soon as you have cached them, you can keep the online version. The cached images should only be used when offline mode is detected or if images fail to show up (see imagesloaded library).

Though doing it this way should be working too, but there must be some problem with the cordova file plugin returning too quickly before the cached file is fully written to the disk, thus this problem.

I have no idea about WP8, any feedback for this platform is welcome!

chrisben avatar Dec 23 '14 09:12 chrisben

@mo3taz-abdallh from another post I've seen you use an old version of cordova, did you try a newer version to see if it fixes this download issue? Did you test ImgCache on Windows 8?

chrisben avatar Feb 08 '15 16:02 chrisben