markmarijnissen / cordova-file-cache Goto Github PK
View Code? Open in Web Editor NEWAn awesome File Cache for Cordova Apps.
License: MIT License
An awesome File Cache for Cordova Apps.
License: MIT License
I got this plugin working for iOS and everything works great. Thanks!
I then went over to the android side, and I'm getting this javascript error when the app loads:
Uncaught (in promise) FileError {code: 12}
...no backtrace - that's really it.
The changes I made to cordova.xml were simply adding this:
<plugin name="cordova-plugin-file" spec="~4.1.1" />
<plugin name="cordova-plugin-file-transfer" spec="~1.5.0" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
JS libs added:
<script type="text/javascript" src="js/lib/CordovaPromiseFS.js" defer></script>
<script type="text/javascript" src="js/lib/CordovaFileCache.js" defer></script>
Initializing the cache like so:
new CordovaFileCache({
fs: new CordovaPromiseFS({Promise: Promise}),
serverRoot: $server_hostname + '/assets/',
localRoot: 'data',
cacheBuster: false
})
...again, this all works perfectly on iOS, so this must be some concern of Android...? Any help would be appreciated. Thank you!
Everything seems to be 'working; properly, with this script. However, I am noticing a ~100 ms time needed to load individual files from cache. Is there any way to speed up this process?
Thanks in advance,
GS
Is it possible to add an auth header to the download request?
Uncaught (in promise) ["http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-95691.jpg"]
Because the onprogress event gets fired for every downloaded file, AND again just 4 lines later, the last item gets a progress event twice. No need for this second one; I would remove it.
in the onDone
inner function in FileCache.download, after
self.list().then(function(){
// final progress event!
if(onSingleDownloadProgress) onSingleDownloadProgress(new ProgressEvent());
// etc...
}
The regex only matches alpha characters. For extensions such as mp4, this results in "mp". The regex should be changed from:
var ext = url.match(/.[a-z]{1,}/g);
to
var ext = url.match(/.[a-z0-9]{1,}/g);
Other non-alphanumeric values may also be valid..
It seems that cordova-file-cache is rejecting promises with non-error objects. This causes bluebird to print warnings, and it seems to totally mess up the stack trace, which is really really unhelpful.
For example, in one instance it rejects with a list of failed files or something:
reject(self.getDownloadQueue());
Please can this be fixed?
Thanks.
Hi,
thanks for your lib. Looks very promising.
I have a problem on init and don't know how to solve it:
TypeError: undefined is not an object (evaluating 'options.Promise')
CrodovaPromiseFS.js line 90.
What I'm doing wrong?
/* Cache */
var cache = CordovaFileCache({
fs: CordovaPromiseFS(),
mode: 'hash', // or 'mirror'
localRoot: 'data',
cacheBuster: false
});
cache.ready.then(function(list){
// Promise when cache is ready.
// Returns a list of paths on the FileSystem that are cached.
console.log('cache is ready');
console.log(list);
});
This is what I'm calling
In hash mode, caching a Vimeo video with an access token results in a .txt
file instead of a .mp4
file. This is with a URL like (for example): https://player.vimeo.com/external/#####.sd.mp4?s=12345abcdef&profile_id=###
The video itself looks like it's saved perfectly fine. Pulling it from a simulator and renaming it from #####.txt
to #####.mp4
results in a video file that plays without problems. The problem is only with the wrong file name, since this messes with other plugin usage (for example, supplying the file://
URL to cordova-plugin-streaming-media).
It looks like the problem is that the plugin is just categorically replacing extensions with .txt
if there's a query string in the URL. I've made a pull request, #17, that fixes the problem.
Hi,
First of all, awesome plugin. I'm really excited to use it.
I had to do some hunting before discovering the license in the bower and npm files, which list the license as MIT. Assuming that's your intended license, GitHub advises "to avoid any potential ambiguity, it's best to include the license file with your project as well." Seeing it spelled-out would make me feel a little more comfortable.
(I believe this applies for cordova-promise-fs as well.)
Best,
Chris
This plugin make use of Promises, that are part of ECMAScript 6 and are still unstable.
http://caniuse.com/#feat=promises
You should add an important note about this.
i noted that he dont download, im using PHP
Headers example
header('Cache-Control: private');
header('Content-Transfer-Encoding: binary');
header('Content-Type: audio/mpeg');
header('Content-Disposition: attachment; filename=a.mp3);
header('Content-Length: 42535355);
I've noticed on oldish HTC One, this statement (in the README) is true:
The plugin requests user permission to use persistent storage at the application first start.
On a newer Nexus, the app doesn't prompt for it at load time, and it doesn't even prompt for it the first time it's used. Further, even after denying the permission, methods from CordovaFileCache.js still seem to work -- download/get/ready/toURL/clear all fine.
So, what exactly is the file permission doing? Is there any way to entirely avoid it?
Here's my example:
cache.add('http://google.com/404.json')
cache.download(()=> {}).then(() => {}, (failedUrls) => { console.log('failedUrls', failedUrls) })
// cache.remove('http://google.com/404.json') // <-- this works
cache.remove('http://google.com/404.json').then(() => {console.log('success')}, () => {console.log('failure')})
Neither success
nor failure
gets logged. My guess from looking at this is that the filesystem promise never resolves / rejects if the file does not exist. Come to think of it, maybe the bug report belongs there?
The change in 'toPath' from:
var ext = url.substr(url.lastIndexOf('.'));
to
var ext = url.match(/\.[a-z]{1,}/g);
means that extensions with numbers in them (e.g. 'mp4') are not matched properly.
I don't know what the change was made for, but perhaps this would work instead:
var ext = url.match(/\.[a-z,0-9]{1,}/g);
Firstly, thanks for an awesome plugin. It came highly recommended and seems to be precisely what we're looking for.
I'm wondering if there are docs somewhere about what type of events the onprogress
callback gets passed?
Specifically, I'm thinking about how to implement a "ready" event for each file. Ideally I'd like to throw some files at the cache, and then trigger a callback when those files have been successfully fetched. My first thought was to try listening to the progress events and then reacting appropriately. Does that approach make sense?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.