Last active
December 20, 2015 23:19
-
-
Save sampottinger/6211231 to your computer and use it in GitHub Desktop.
Loads a local file into the current PhoneGap application's temporary directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Thanks http://stackoverflow.com/questions/16065494 | |
// WARNING: Untested. Please provide feedback. | |
/** | |
* Request a local file into the PhoneGap application's temporary directory. | |
* | |
* Get a local file into the the current PhoneGap application's temporary | |
* directory given a larger filesystem file URI. | |
* | |
* @param {String} uri The URI to load the file from. | |
* @param {function} onReady Function to call after the file has been loaded. | |
* This function should take a single argument: a PhoneGap File object | |
* instance. | |
* @param {function} onError Function to call if an error is encountered while | |
* loading the file. Should take a single argument: an Error object. | |
**/ | |
function getLocalFileFromTemp(uri, onReady, onError) | |
{ | |
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(fs){ | |
fs.root.getFile("temp", {create: true, exclusive: false}, | |
function(entry){ | |
fileTransfer.download( | |
fileURI, // the filesystem uri you mentioned | |
entry.fullPath, | |
function(entry) { | |
onReady(entry); | |
}, | |
function(error) { | |
onError(error); | |
}, | |
false, | |
null | |
); | |
}, function(){ | |
onError('File create error.'); | |
}); | |
}, null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment