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

Failed to cache files on local file system

Open confile opened this issue 10 years ago • 13 comments

I tried to cache a file with is on my iPhone 5 iOS 7.1.1 at:

/var/mobile/Applications/220B3516-0877-4A8C-AF84-DC05E4F2F051/Documents/ImageFile-349402272.png

Here is what I get in the debug console having debug = true:

ERROR: Download error source: /var/mobile/Applications/220B3516-0877-4A8C-AF84-DC05E4F2F051/Documents/ImageFile-349402272.png
ERROR: Download error target: file:///var/mobile/Applications/220B3516-0877-4A8C-AF84-DC05E4F2F051/Documents/imgcache//044eaad7240479f25687a16bf91dfe3b9a602ece.png
ERROR: Download error code: 3

There is a url in the cache folder but the caching did fail. I did isCached and it returned false.

confile avatar Dec 04 '14 23:12 confile

Hi,

Without giving the code you use to generate this error, I doubt anybody will be able to help you correctly ;)

BrunoCartier avatar Dec 05 '14 09:12 BrunoCartier

Here is the code:

var url = "/var/mobile/Applications/220B3516-0877-4A8C-AF84-DC05E4F2F051/Documents/ImageFile-349402272.png";
ImgCache.init(function(){
    alert('ImgCache init: success!');

 ImgCache.cacheFile(url);
}, function(){
    alert('ImgCache init: error! Check the log for errors');
});

confile avatar Dec 05 '14 10:12 confile

I'm not very familiar with the iOS platform, but the problem seems to "simply" be that it's not possible to access (GET) your image, either because it doesn't exist, or there is a access permission issue.

Make a HTTP request targeting the URI of your image, then log the result of this request. The error code will probably help. Also, you should see the doc for the File Plugin in iOS, because to access a file, if I'm not mistaken, the protocol is something special, like file:// or cdvfile://.

BrunoCartier avatar Dec 05 '14 10:12 BrunoCartier

I can access the image. I put it in a tag and it gets displayed. So the image exists.

I also have this in my config.xml

    <platform name="android">
        <preference name="AndroidPersistentFileLocation" value="Internal" />
    </platform>

    <platform name="ios">
        <preference name="iosPersistentFileLocation" value="Library" />
    </platform>

confile avatar Dec 05 '14 12:12 confile

Which Cordova version are you using? It seems that this bug has been found in 3.3 & 3.4.

BrunoCartier avatar Dec 05 '14 13:12 BrunoCartier

I use the latest version 4.1.2.

confile avatar Dec 05 '14 14:12 confile

The bug you mentioned is from Android. I am working on iOS. I think the problem is that I want to cache a file which is still on the local file system of the device. This means that requesting it with a HTTP GET might not work.

I think that imgcache.js should check if the imageUrl to be cached starts with

/var

if this is the case it should not use HTTP GET instead it should use the file api to access the file.

confile avatar Dec 05 '14 14:12 confile

ImgCache is not meant to cache files that don't need to be cached (local files) so I don't expect it to work in that case. It is meant to cache online files (off the web) in case you get offline.

@confile , what were you trying to achieve there?

chrisben avatar Dec 05 '14 23:12 chrisben

I try to copy the local image file fr the library in the cache folder. In case the user deletes the file from the library I would still have a copy in the cache to be used.

How would you do that?

confile avatar Dec 06 '14 09:12 confile

I suggest you have a look at the Cordova File plugin directly. Then you could implement something like this I guess.

chrisben avatar Dec 08 '14 15:12 chrisben

@confile any news on that? v1.0rc1 is out now, it includes a fix for paths with iOS cordova targets. Let me know if that fixes your problem.

chrisben avatar Feb 08 '15 16:02 chrisben

'ERROR: Download error code: 3' I also had a similar error. It works now by adding "cordova-plugin-whitelist".

cordova plugin add cordova-plugin-whitelist otherwise http requests are blocked - as of the latest Cordova version.

Dreampassport avatar Aug 30 '15 16:08 Dreampassport

'ERROR: Download error code: 3' I also had a similar error. It works now by adding "cordova-plugin-whitelist".

cordova plugin add cordova-plugin-whitelist otherwise http requests are blocked - as of the latest Cordova version.

Thank's! This is worked for me on android device. Also need to make right link on local file.

maximnara avatar Feb 07 '21 20:02 maximnara