I tried to resolve the file that is produced by navigator.device.capture [I know there are other ways to capture images, but using this for all media] and it gets failing at the fileSystem.root.getFile.
I am able to display the image using other code - so I know the file is there. [example: -- var/mobile/Applications/AFEAGDDD-A765-7B888989766/tmp/photo_001.jpg)
Also, instead used the fileSystem.root.getDirectory followed by getFile as shown (commented below- but fails also.)
I tried to remove the leading '/' add leading 'file:///' etc- but does not work. please Help!
I am able to display the image using other code - so I know the file is there. [example: -- var/mobile/Applications/AFEAGDDD-A765-7B888989766/tmp/photo_001.jpg)
Also, instead used the fileSystem.root.getDirectory followed by getFile as shown (commented below- but fails also.)
I tried to remove the leading '/' add leading 'file:///' etc- but does not work. please Help!
navigator.device.capture.captureImage(captureSuccess, captureError, {limit: 1});
function captureSuccess(mediaFile) {
var path = mediaFile[0].fullPath; // -- /var/mobile/Applications/AFEAGDDD-A765-7B888989766/tmp/photo_001.jpg
var name = mediaFile[0].name; // -- photo_001.jpg
my_fullpath = path.substring(1) // removed the leading '/' // -- var/mobile/Applications/AFEAGDDD-A765-7B888989766/tmp/photo_001.jpg
//my_fullpath = 'file://'+path; // added leading 'file:///' // -- file:///var/mobile/Applications/AFEAGDDD-A765-7B888989766/tmp/photo_001.jpg
just_path = path.substring(1, path.lastIndexOf("/")); // -- var/mobile/Applications/AFEAGDDD-A765-7B888989766/tmp/
just_file = path.substring(path.lastIndexOf("/")+1); // -- photo_001.jpg
alert('just_path = '+just_path);
alert('just_file = '+just_file);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, FS, fail1);
}
function FS(fileSystem) {
// try {
// var dataDir = fileSystem.root.getDirectory(just_path, {create : true, exclusive : false });
// dataDir.getFile(just_file, {create : true, exclusive : false }, gotFileEntry, fail2);
// } catch(err){alert('error at getDirectory: ' + err.message);}
try{
fileSystem.root.getFile(my_fullpath, {create : true, exclusive : false }, gotFileEntry, fail2);
} catch(err){alert('error at fileSystem.root.getFile: ' + err.message);}
}
function gotFileEntry(fileEntry) {
alert('In gotFileEntry - fileEntry.name = ' + fileEntry.name);
alert('In gotFileEntry- fileEntry.fullPath = ' + fileEntry.fullPath);
window.resolveLocalFileSystemURI(fileEntry.fullPath, onResolveSuccess, onResolveFail);
}
function captureError(error) {
alert('Error capture image: '+error.code);
}
function fail1(error) {
alert('Error getting LocalFileSystem: '+error.code);
}
function fail2(error) {
alert('Error getFile :'+error.code);
}
function onResolveSuccess(fileEntry) {
alert('In onResolveSuccess - Success'+fileEntry.name);
}
function onResolveFail(error) {
alert('In onResolveFail - Issue with Resolve: '+error.code);
}
function captureSuccess(mediaFile) {
var path = mediaFile[0].fullPath; // -- /var/mobile/Applications/AFEAGDDD-A765-7B888989766/tmp/photo_001.jpg
var name = mediaFile[0].name; // -- photo_001.jpg
my_fullpath = path.substring(1) // removed the leading '/' // -- var/mobile/Applications/AFEAGDDD-A765-7B888989766/tmp/photo_001.jpg
//my_fullpath = 'file://'+path; // added leading 'file:///' // -- file:///var/mobile/Applications/AFEAGDDD-A765-7B888989766/tmp/photo_001.jpg
just_path = path.substring(1, path.lastIndexOf("/")); // -- var/mobile/Applications/AFEAGDDD-A765-7B888989766/tmp/
just_file = path.substring(path.lastIndexOf("/")+1); // -- photo_001.jpg
alert('just_path = '+just_path);
alert('just_file = '+just_file);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, FS, fail1);
}
function FS(fileSystem) {
// try {
// var dataDir = fileSystem.root.getDirectory(just_path, {create : true, exclusive : false });
// dataDir.getFile(just_file, {create : true, exclusive : false }, gotFileEntry, fail2);
// } catch(err){alert('error at getDirectory: ' + err.message);}
try{
fileSystem.root.getFile(my_fullpath, {create : true, exclusive : false }, gotFileEntry, fail2);
} catch(err){alert('error at fileSystem.root.getFile: ' + err.message);}
}
function gotFileEntry(fileEntry) {
alert('In gotFileEntry - fileEntry.name = ' + fileEntry.name);
alert('In gotFileEntry- fileEntry.fullPath = ' + fileEntry.fullPath);
window.resolveLocalFileSystemURI(fileEntry.fullPath, onResolveSuccess, onResolveFail);
}
function captureError(error) {
alert('Error capture image: '+error.code);
}
function fail1(error) {
alert('Error getting LocalFileSystem: '+error.code);
}
function fail2(error) {
alert('Error getFile :'+error.code);
}
function onResolveSuccess(fileEntry) {
alert('In onResolveSuccess - Success'+fileEntry.name);
}
function onResolveFail(error) {
alert('In onResolveFail - Issue with Resolve: '+error.code);
}
Comment