Richard
Richard

Reputation: 1158

Blackberry File (Webworks)

I'm trying (Very simply) to get a file list of the camera directory using webworks. The code I'm trying is as follows:

function displayPhotos(id) {
try {
    var Dir, path, items;

    if ((window.blackberry === undefined) || (blackberry.io === undefined) || (blackberry.io.file === undefined)) {
        appendContent("photoDetails", "<p><i><b>blackberry.io.file</b> object not found (likely cause is WebWorks APIs are not supported by this user agent).</i></p>");
        debug.log("displayPhotos", "blackberry.io.file object is undefined.", debug.error);
        return false;
    }

    Dir = blackberry.io.dir;

    path = "";      
    path = "file:///Device/home/user/camera"";


    items = Dir.listFiles(path);

    console.log(items);

    //setContent(id, formatAsHTML(path, items));

}
catch(e) {
    console.log("displayPhotos", e, debug.exception);
}
}

All I get back is error 1004 - I assume this is permissions based, but I fail to believe I can't get a READ on the camera fails - any one know anything?

Cheers!

Upvotes: 0

Views: 621

Answers (1)

Richard
Richard

Reputation: 1158

Well I figured it out, hope this helps anyine getting the dreaded blackberry webworks error 1004.

You need to change device in the path to store. That's it really. This example works:

function displayPhotos(myFolder) {
    try {
        var Dir, path, items;       
        Dir = blackberry.io.dir;

    path = "";      
    if (myFolder != undefined){
        path = myFolder;
    } else {
        path = "file:///store/home/user/pictures";
        //file:///store/home/user/camera
    }

    items = Dir.listFiles(path);        
    return items;
}
catch(e) {
    console.log("displayPhotos", e, debug.exception);
}
}


function displayFiles(myFolder) {
try {
    console.log("displayFiles", "in " + myFolder);
    return displayPhotos(myFolder);
}
catch(e) {
    console.log("displayFiles", e, debug.exception);
}
}

You can call it like so:

 displayFiles();

Or specify a folder like so:

 displayFiles("file:///store/home/user/camera");

Returns an array of filenames.

Hope this helps someone!

Upvotes: 2

Related Questions