Comments (4)
I use a simple method for download files,
// need chrome --disable-web-security or whitelist in manifest!
/**
* download up and return a local url string for a given URL entry.
*
* @param {string} url a file url
* @param {string|FileEntry} entryOrPath A path, filesystem URL, or FileEntry
* of the file to lookup.
* @param {Function} successCallback Success callback passed the File object.
* @param {Function=} opt_errorHandler Optional error callback.
*/
Filer.prototype.download = function(remoteURL, entryOrPath, successCallback, opt_errorHandler)
{
var xhr = new XMLHttpRequest();
xhr.responseType='blob';
xhr.open("GET", remoteURL, true);
tmp_filer = this;
xhr.onload = function(e)
{
if(this.status == 200)
{
var buff = xhr.response;
tmp_filer.write(entryOrPath, {data: buff, type: buff.type}, function(fileEntry, fileWriter)
{
if(successCallback) successCallback(fileEntry.toURL());
}, opt_errorHandler);
}
else
{
if(opt_errorHandler) opt_errorHandler();
}
}
xhr.onerror = function (e) {if(opt_errorHandler) opt_errorHandler();}
xhr.send();
}
test_filer = new Filer();
test_filer.init({persistent: true, size: 5*1024*1024}, function(fs)
{
test_filer.download('http://learningfromdogs.files.wordpress.com/2010/09/cats-in-sink.jpg', './cats-in-sink.jpg', function (path) {console.log(path);});
}, function () {console.log(error)});
from filer.js.
Just a simple question. If I only need to download files hosted in my domain I will not get Origin is not allowed by Access-Control-Allow-Origin errors?
I am writing an application that downloads texture packs in ZIP format, and caches them in the FileSystem. All packs will be provided by the same server, so I do not think there will be issues, but I would like to make confirm that.
from filer.js.
Correct. If you're XHRing files from the same origin, you won't get errors or need to use flags.
@micheg it's a really bad idea to turn on --disable-web-security
in your primary browser :(
from filer.js.
I used it not in the system browser, I used this method inside an app in a chromium portable browser, created for the purpose.
Now I'm rewriting that app for nw.js, I'm still undecided whether to use the HTML5 storage or node modules for filesystem.
from filer.js.
Related Issues (20)
- Compatible common js HOT 1
- Getting qunit into the repo
- "FileError is deprecated" HOT 3
- Illegal Constructor (Blob) when working with Jelly Bean Android (Cordova) HOT 3
- Uncaught error when trying to filer.open() a directory HOT 2
- Filer.find HOT 1
- how can i continual read realtime mp3 buffer to the temporary MP3 file?Can anyone help?Thanks!! HOT 2
- mkDir issues
- Rename Util class HOT 3
- License HOT 1
- Where on my disk can I find file I have created? HOT 3
- File moving should not be done on a patch version HOT 1
- Getting an error while creating simple persistent file HOT 2
- directories not working HOT 4
- synchronous functions HOT 6
- compatibility with Cordova File Plugin HOT 1
- error seeking persistent file permission
- Need a better way to import filer.js for Vue.js HOT 1
- self.requestFileSystem returns SecurityError when running as a Chrome App. HOT 2
- Preview DXF (Catia) files
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from filer.js.