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
BlackBerry Development Advisor
bryanhiggins
Posts: 187
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

If you look at the cordova FileTransfer API, it uses resolveLocalFileSystemURI internally, which explains why you get the same error:

 

https://github.com/apache/cordova-js/blob/master/lib/blackberry/plugin/qnx/fileTransfer.js

 

I have logged a bug for this in cordova. Look out for a patch soon:

 

https://issues.apache.org/jira/browse/CB-2901

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Please use plain text.
Developer
jeff_sawatzky
Posts: 29
Registered: ‎04-01-2013
My Device: Z10
My Carrier: Rogers

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

[ Edited ]

I tried your window.requestFileSystem suggestion, and I still can't get it to work. I have updated my example on StackOverflow to test it. I beleive I am doing everything correctly.

 

The example now has three buttons, each one allows you to test a different thing:

1) resolve the local file system URI using the imageURI

2) try to do a FileTransfer directly using the imageURI

3) get a filesystem and then try to get the file through filesystem.root.getFile with the imageURI

 

In each case, the call fails with error code 1 (file not found)

Please use plain text.
Developer
jeff_sawatzky
Posts: 29
Registered: ‎04-01-2013
My Device: Z10
My Carrier: Rogers

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

I've noticed that the filesystem I get back is always "temporary" even though I asked for the persistent one. Perhaps this has to do with it?

Please use plain text.
Contributor
kdart89
Posts: 10
Registered: ‎03-26-2013
My Device: BlackBerry Z10
My Carrier: Vodafone

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

I noticed that earlier. However, the fullPath points to "local:///persistent" so it's just a name issue. I think they point to where they're meant to in the back end.
Please use plain text.
Developer
jeff_sawatzky
Posts: 29
Registered: ‎04-01-2013
My Device: Z10
My Carrier: Rogers

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

Bryan, haven't heard anything back from you regarding my issues with the following steps you suggested:

1) blackberry.io.sandbox = false
2) window.requestFileSystem
3) root.getFile

 

Is there an issue there as well? Or am I doing something wrong?

Please use plain text.
Contributor
kdart89
Posts: 10
Registered: ‎03-26-2013
My Device: BlackBerry Z10
My Carrier: Vodafone

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

Hi Jeff,

 

What happens if you do the following:

fs.root.getFile(
    myFileName.replace("file://", ""),
    {create: true},
    function(file) {

    },
    function(err) {

    }
);

 

(where fs is the returned fileSystem from window.requestFileSystem)?

 

I found an issue with reading files using the 'file' protocol, so stripped that bit out - and it worked for me afterwards.

 

Still leave blackberry.io.sandbox = false.

Please use plain text.
Contributor
kdart89
Posts: 10
Registered: ‎03-26-2013
My Device: BlackBerry Z10
My Carrier: Vodafone

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

Apologies - that {create: true} is meant to read {create: false} since we don't want to create it if it's not there.

Please use plain text.
BlackBerry Development Advisor
bryanhiggins
Posts: 187
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

[ Edited ]

Here is a working WebWorks example of invoking the camera card, reading the file and uploading to a server.

 

I'm currently looking at how the cordova file API could be improved so that BB10 is consistent with the other platforms. I definitely appriciate your feedback on that so far. It seems that there are already some inconsistencies between the other major platforms and that likely boils down to differences in the actual file system.

 

<html>
<head>
<script type="text/javascript" src="local:///chrome/webworks.js"></script>
<script type="text/javascript">

function log(e) {
    console.log(e);
}

function takePicture(success) {
    blackberry.invoke.card.invokeCamera('photo', function (path) {
        success(path);
    }, log, log);
}

function openFile (filePath, success) {
    window.webkitRequestFileSystem(window.PERSISTENT, 1024*1024*1024, function (fs) {
        fs.root.getFile(filePath, {}, function (entry) {
            success(entry);
        }, log);
    }, log);
}

function uploadFile (entry, server, success) {
    entry.file(function (file) {
        var fd = new FormData(),
            xhr;
        fd.append("picture", file);
        xhr = new XMLHttpRequest();
        xhr.open("POST", server);
        xhr.onload = function (evt) {
            if (xhr.status == 200) {
                success(xhr.response);
            } else {
                log(xhr);
            }
        };
        xhr.ontimeout = log;
        xhr.onerror = log;
        xhr.send(fd);
    }, log);
}

function start() {
    takePicture(function (filePath) {
        openFile(filePath, function (entry) {
            uploadFile(entry, "http://cordova-filetransfer.jitsu.com/upload", function () {
                alert("SUCCESS");
            });
        });
    });
}

document.addEventListener('webworksready', function () {
    blackberry.io.sandbox = false;
    document.getElementById("startButton").disabled = "";
});

</script>
</head>
<body>
<h1>Camera XHR Upload Sample</h1>
<button id="startButton" disabled="disabled"  onclick="start();">Start</button>
</body>
</html>

 

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
        xmlns:rim="http://www.blackberry.com/ns/widgets"
	version="1.0.0.0" id="com.blackberry.cameraUpload">

  <name>Camera Upload Example</name>

  <author>Bryan Higgins</author>

  <description>
       A sample WebWorks application for uploading a file via XHR
  </description>
    
  <feature id="blackberry.io" />
  <feature id="blackberry.invoke.card" />

  <content src="index.html" />

<access subdomains="true" uri="http://cordova-filetransfer.jitsu.com/" />

  <rim:permissions>
    <rim:permit>use_camera</rim:permit>
    <rim:permit>access_shared</rim:permit>
  </rim:permissions>

</widget>

 

 

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Please use plain text.
Contributor
kdart89
Posts: 10
Registered: ‎03-26-2013
My Device: BlackBerry Z10
My Carrier: Vodafone

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

Thanks Bryan - this is most useful. One final question, is there a way to control the picture size like on other platforms?

Currently my images are being returned at (roughly) 3000x1200px which is quite a bit larger than necessary.

If there is then great, if not then I'll have to do some manual intervention to reduce them.

Thanks.
Please use plain text.
BlackBerry Development Advisor
bryanhiggins
Posts: 187
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

There is no way to control image size. You'll have to resize after taking the photo.

 

The camera card only allows you to specify the mode: photo, video or full.

 

http://developer.blackberry.com/html5/apis/blackberry.invoke.card.html#.CAMERA_MODE_PHOTO

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Please use plain text.