Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 125
Registered: ‎10-02-2011
My Device: Playbook
My Carrier: none

PhoneGap Camera Files

I'm trying to figure out how to list the files that are in the camera folder. I'm looking mostly at the File API on PhoneGap, but maybe it's not possible to do it with this. Can someone point me in the right direction?

 

<script type="text/javascript" src="cordova.js"></script> 
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
	//request the file system
	window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
}
function onFileSystemSuccess(fileSystem) {
	alert(fileSystem.name);
	alert(fileSystem.root.name);
	//move to camera folder
	//list the files
}
function fail(evt) {
	alert(evt.target.error.code);
}
</script>

 

Retired
Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10
My Carrier: Bell

Re: PhoneGap Camera Files

This looked promising:

 

http://docs.phonegap.com/en/2.8.0/cordova_file_file.md.html#DirectoryReader

 

So, I suppose once you have the root of the filesystem as you do in your code snippet, you could do the following:

 

fileSystem.root.getDirectory(blackberry.io.sharedFolder + '/camera', { create: false }, function(dir) {

    dir.createReader().readEntries(successFN, failFN);

});

 

You'll need to include the blackberry.io extension to obtain the shared directory (or, you can substitute it with '/accounts/1000/shared' but that's not recommended).

 

Hope this helps point you in the right direction Smiley Happy

 

-Ham

 

------------------------------
@grahamzibar
-_- zZZ
Developer
Posts: 125
Registered: ‎10-02-2011
My Device: Playbook
My Carrier: none

Re: PhoneGap Camera Files

[ Edited ]

I'm still not able to get the contents of the camera directory. Any ideas? 

 

Update: This code is working.

 

// un-sandbox file system to access shared folder
blackberry.io.sandbox = false;

window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
    fs.root.getDirectory(blackberry.io.sharedFolder + '/camera', {
        create: false
    }, function(dir) {
        dir.createReader().readEntries(function success(entries) {
            var i;
            for (i = 0; i < entries.length; i++) {
                console.log(entries[i].name);
            }
        }, function fail(error) {
            alert("Failed to list directory contents: " + error.code);
        });
    });
});