chrisben / imgcache.js

JS library based on the File API to cache images for offline recovery (target: cordova/phonegap & chrome)
Other
826 stars 216 forks source link

v1.0rc2 breaks on Android #148

Closed outerbound closed 8 years ago

outerbound commented 8 years ago

I upgraded to v1.0rc2. Imgcache is totally broken on Android. I checked logs, Why is cdvfile:// coming for Android? I reverted back to v1.0rc1 and things are back to normal.

rc2 log

INFO: ImgCache initialising INFO: LocalFileSystem opened INFO: Local cache folder opened: cdvfile://localhost/persistent/ImgCache/ INFO: .nomedia file created. cdvfile://localhost/persistent/ImgCache/31ce96647d9ebd5b22332116d74232a03bca3fbd.jpg Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/ImgCache/a797e4a94395220a55f99135604f4f26779eb353.png Failed to load resource: the server responded with a status of 404 (Not Found)

rc1 log

INFO: ImgCache initialising INFO: LocalFileSystem opened INFO: Local cache folder opened: file:///storage/emulated/0/ImgCache/ INFO: .nomedia file created.

chrisben commented 8 years ago

I suppose this is a regression caused by this change: https://github.com/chrisben/imgcache.js/commit/9160fb4d6609011e0796d5c124117965f655224f That seemed to fix things for some people (see #97)

Could you please:

ksibod commented 8 years ago

I'm not sure if @outerbound was able to fix their issue or not, but I was having the same problem. @chrisben You are correct that commenting out the three lines added in 9160fb4 solved the issue.

This is with:

chrisben commented 8 years ago

Thanks @ksibod for the feedback! Perhaps then those lines of code should only be kept for iOS then.. Reading the comments on #97 suggests most people saying it fixed their problems were iOS user. @ksibod or @outerbound : would you be able to test your application on iOS ?

eekilli commented 8 years ago

Hi, maybe not completely related to this issue, but I was having 404 errors using ImgCache on Android (4.0+) with Cordova 5. After much trial and error I found the solution of adding <access origin="cdvfile://*" /> to my config.xml. (If you use the whitelist plugin you probably have to add <allow-intent href="cdvfile://*" /> as well)

I could not find anything about this in the CORDOVA.md, so would be nice if someone could add this to prevent anyone else having the same headache :)

ksibod commented 8 years ago

@chrisben No problem! I did test this on iOS as well. For my application, there was no error either way. Commenting those lines out didn't change anything at all. This was on an iPhone 6 with iOS 9.1.

JumpLink commented 8 years ago

Same problem and fixed with @eekilli's solution (I havn't comment out anything), thank you! See also this similar issue.

I think this issue is resolved?

SamVerschueren commented 8 years ago

I confirm adding <access origin="cdvfile://*" /> to the config.xml file fixes this problem.

chrisben commented 8 years ago

Great, I'm adding this info to the documentation. Thanks @eekilli

vdias38 commented 8 years ago

I still observe this issue. I've migrated from imgcache.js#v1.0rc1 to imgcache.js#v1.0.0 and stop working on Android. Works well on iOS. If I do the reverse migration, re-install version 1.0rc1 it works back. I've tested with phonegap cli-6.0.0 (Android 5.1.0) and File plugin 4.1.0. My device run with Android 4.1. On my config.xml I've setted both lines:

<access origin="cdvfile://*" />
<allow-intent href="cdvfile://*" />

Can't see errors in logs

[phonegap] [console.log] INFO: ImgCache initialising
[phonegap] [console.log] INFO: LocalFileSystem opened
[phonegap] [console.log] INFO: Local cache folder opened: cdvfile://localhost/persistent/imgcache/
[phonegap] [console.log] INFO: .nomedia file created.
chrisben commented 8 years ago

@elbidone would that be possible for you to track when that regression occurred by testing the successive commits following rc1? You can use dichotomy to speed up the process there. Sorry I make you work there, but I don't have all the environment to reproduce your issue.

vdias38 commented 8 years ago

Hi @chrisben, I've finally found the issue.

After days of investigation (I've tested various versions of phonegap and File plugin), the solution comes from a PhoneGap Community Issue: cdvfile throws 404 not found error in Phonegap 5.1.1 . It only works for me if I declare on my config.xml:

<access origin="cdvfile://*" />
<allow-navigation href="cdvfile://*" />

If I remove <allow-navigation href="cdvfile://*" /> it raises 404.

I didn't need to add cdvfile scheme on my CSP or <allow-intent href="cdvfile://*" /> on my config.xml. Below my CSP.

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src self' 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'; img-src * filesystem:;">

Thanks for your reply, this issue was an opportunity do dig deeper into imgcache.js code, congratulations it's very well implemented and commented!!

chrisben commented 8 years ago

@elbidone Thanks for sharing your findings with us, hope this will help other people in the same case.

badpenguin commented 7 years ago

Well.... i've this same problem and reverted back to rc1. I've tried rc2 just now with ionic2 because i was happy with the old 0.xx release i was using with ionic1