Just getting started with PhoneGap File API / Cordova 3.0 and I have a little issue looking up a file using getFile(). Don't know if the chaining is wrong. Or just missing the obvious...
I get to gotFS, passing in the full path as file:///storage/emulated/0/DCIM/Camera/... and the result is an error 5. I am guessing the path is not correct, or I can't get to storage/emulated?
The whole point is to return the file as a base64-encoded data URL e.g.,readAsDataURL.
// I just finished taking a video
//
function captureSuccess(mediaFile) {
// Store the results
//
window.media = mediaFile;
// Get started with the file request
//
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
function gotFS(fileSystem) {
// Get the path of the file
// Will return something like //file:///storage/emulated/0/DCIM/Camera/....
//
var fullPath = window.media[0].fullPath;
// Let's try and resolve, make sure I'm not crazy. I might be.
//
window.resolveLocalFileSystemURI(fullPath, winConvert, failConvert);
function winConvert(uri){
// The resolve matches file location stored at window.media
//
console.log(uri);
}
function failConvert(error){
console.log('Something happend resolving uri: '+error.code);
}
fileSystem.root.getFile(fullPath, null, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
console.log('gotFileEntry');
fileEntry.file(gotFile, fail);
}
function gotFile(file){
console.log('gotFile');
readDataUrl(file);
}
function readDataUrl(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log(evt.target.result);
};
reader.readAsDataURL(file);
}
function fail(error) {
console.log(error.code);
}
}