I am working on iPhone app using PhoneGap.
In this app I need to show a screen with camera roll pictures and the user should be able to select multiple photos from it.
Using navigator.camera.getPicture
I can show all images, but user can select only one image from it.
The imageURI returned is
file://localhost/var/mobile/Applications/946FDEC2-E166-4209-94F8-5E2C70EEDA71/tmp/cdv_photo_010.jpg
And tried with file api as below.
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
// success get file system
var sdcard = fileSystem.root;
sdcard.getDirectory("../../../Media/DCIM/100APPLE",
{create:false, exclusive: false},
function(dcim){
var directoryReader = dcim.createReader();
directoryReader.readEntries(function(entries){
// success get files and folders
for(var i=0; i<entries.length; ++i){
alert(entries[i].name);
}
});
}, function(error){
switch(error.code){
case FileError.NOT_FOUND_ERR : alert('NOT_FOUND_ERR');break;
case FileError.SECURITY_ERR: alert('SECURITY_ERR');break;
case FileError.ABORT_ERR: alert('ABORT_ERR');break;
case FileError.NOT_READABLE_ERR: alert('NOT_READABLE_ERR');break;
case FileError.ENCODING_ERR: alert('ENCODING_ERR');break;
case FileError.NO_MODIFICATION_ALLOWED_ERR: alert('NO_MODIFICATION_ALLOWED_ERR');break;
case FileError.INVALID_STATE_ERR: alert('INVALID_STATE_ERR');break;
case FileError.SYNTAX_ERR: alert('SYNTAX_ERR');break;
case FileError.INVALID_MODIFICATION_ERR: alert('INVALID_MODIFICATION_ERR');break;
case FileError.QUOTA_EXCEEDED_ERR: alert('QUOTA_EXCEEDED_ERR');break;
case FileError.TYPE_MISMATCH_ERR: alert('TYPE_MISMATCH_ERR');break;
case FileError.PATH_EXISTS_ERR: alert('NOT_FOUND_ERR');break;
}
});
This works in simulator.
But when tried in iPhone it shows error and there is no DCIM
folder inside ../../../Media
in the iPhone.
My iPhone model is iPhone 4S 16Gb with iOS 6.0
I would like to know
- Is there anything wrong with this approach?
- What is the correct path instead of
../../../Media/DCIM/100APPLE
in which the camera roll pictures are saved? - Is there any meta files in which the above mentioned path is stored?
- Is there any other method to achieve this (option to select multiple files from camera roll) ?