Skip to content

Instantly share code, notes, and snippets.

@blackrabbit99
Created February 18, 2013 21:08
Show Gist options
  • Save blackrabbit99/4980755 to your computer and use it in GitHub Desktop.
Save blackrabbit99/4980755 to your computer and use it in GitHub Desktop.
loadFromUrl = function (params, callback) {
'use strict';
var onError = function (err) {
callback(err, null);
};
params.newFileName = params.newFileName || params.urlPath.substr(params.urlPath.lastIndexOf('/') + 1);
params.expansion = params.expansion || '';
params.mimeType = params.mimeType || 'text/plain';
requestFileSystem(window.LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
fileSystem.root.getDirectory("folder", {"create": true, "exclusive": false}, function () {
fileSystem.root.getDirectory("folder/" + params.localPathName, {"create": true, "exclusive": false}, function (dir) {
var options = new FileUploadOptions(),
fileTransfer = new FileTransfer();
options.fileKey = "file";
options.fileName = params.newFileName;
options.mimeType = params.mimeType;
fileTransfer.download(params.urlPath, dir.fullPath + '/' + params.newFileName + params.expansion, function (entry) {
callback(null, entry.fullPath);
}, onError, options);
}, onError);
}, onError);
}, null);
};
loadFromUrl({
"urlPath": "http://img.likez.ru/20130219/th_9jZqc9bPJis.jpg",
"localPathName": 'avatars',
"mimeType": 'image/jpeg',
"newFileName": 'th_9jZqc9bPJis.jpg',
"expansion": '.jpeg'
}, function (err, imgURI) {
console.log(imgURI);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment