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
Highlighted
New Contributor
Posts: 9
Registered: ‎03-13-2014
My Device: N/A
My Carrier: N/A
Accepted Solution

Cordova 3.4 / File plugin 1.0.1 - resolveLocalFileSystemURL for camera image

[ Edited ]

I'm having a problem with a bit of code that is working on Android 2.3 - 4.4 and iOS 5 - 7.  In a nutshell it calls the camera api getPicture method which successfully returns a file URI.  An example of this URI is as follows:

 

file:///accounts/1000/shared/camera/IMG_0000025.jpg

 

It then takes this file URI and tries to resolve a file entry for it like so:

 

window.resolveLocalFileSystemURL(fileUri, success, fail);

 

Note that this is now URL instead of URI.  URI was deprecated as of version 1.0.0 of the file plugin.  The error callback (fail in the above example) is always called.  It is passed an error object like the API says it should. It has 1 property on it called "code" but instead of being one of the numbers that would indicate what kind of file error is happening the code property is just null.

 

I also tried changing the URI to exclude the file:// portion of the path but the resolveLocalFileSystemURL then returns an error with code 5 (encoding error).

 

I made sure that I added this to the config.xml:

 

<access origin="file:///" subdomains="true" />

 

And I also made sure that the config.xml after running a cordova build has the permission for shared access:

 

<rimSmiley Tongueermissions>
   <rimSmiley Tongueermit>access_shared</rimSmiley Tongueermit>
   <rimSmiley Tongueermit>read_device_identifying_information</rimSmiley Tongueermit>
</rimSmiley Tongueermissions>

 

Anyone have insight into what might be causing this?

 

Thanks.

Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: Cordova 3.4 / File plugin 1.0.1 - resolveLocalFileSystemURL for camera image

Hi,

 

Thanks for the report! I've logged an issue to ensure this gets fixed in the next plugins release.

 

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

 

You can work around this by using resolveLocalFileSystemURI instead:

 

if (cordova.platformId === "blackberry10") {
    window.resolveLocalFileSystemURL = window.resolveLocalFileSystemURI;
}

 

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
New Contributor
Posts: 9
Registered: ‎03-13-2014
My Device: N/A
My Carrier: N/A

Re: Cordova 3.4 / File plugin 1.0.1 - resolveLocalFileSystemURL for camera image

This was actually the very first thing I tried but they both follow the same code path.  You can see in cordova's plugin when you call resolveLocalFileSystemURI it is just forwarding the call to the new method:

 

module.exports.resolveLocalFileSystemURI = function() {
   console.log("resolveLocalFileSystemURI is deprecated. Please call resolveLocalFileSystemURL instead.");
   module.exports.resolveLocalFileSystemURL.apply(this, arguments);
};

 

The result is the same though, the error callback is invoked and the error object has a null code property.

Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: Cordova 3.4 / File plugin 1.0.1 - resolveLocalFileSystemURL for camera image

You should not see that console.log on BB10 due to this entry in plugin.xml

 

<js-module src="www/blackberry10/resolveLocalFileSystemURI.js" name="BB10resolveLocalFileSystemURI">
    <clobbers target="window.resolveLocalFileSystemURI" />
</js-module>

 

I tested out your scenario with cordova 3.4.0-0.1.3 to confirm my suggested patch works

 

    onDeviceReady: function() {
        if (cordova.platformId === "blackberry10") {
            window.resolveLocalFileSystemURL = window.resolveLocalFileSystemURI;
        }
    },
    takePicture: function () {
        navigator.camera.getPicture(function (url) {
            window.resolveLocalFileSystemURL(url, function (file) {
                console.log("FILE", file);
            }, function () { console.log("ERROR", arguments) });
        });
    }

 

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
New Contributor
Posts: 9
Registered: ‎03-13-2014
My Device: N/A
My Carrier: N/A

Re: Cordova 3.4 / File plugin 1.0.1 - resolveLocalFileSystemURL for camera image

Thanks Bryan - you are right.

 

I just tried your example though and it never makes it to either of the resolveFileSystemURI's callbacks.  Neither the success or failure callbacks are called.  Any ideas on what I could be doing wrong?

Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: Cordova 3.4 / File plugin 1.0.1 - resolveLocalFileSystemURL for camera image

If you post the full source, I can take a look. I'm using file plugin 1.0.1.

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
New Contributor
Posts: 9
Registered: ‎03-13-2014
My Device: N/A
My Carrier: N/A

Re: Cordova 3.4 / File plugin 1.0.1 - resolveLocalFileSystemURL for camera image

Hi Bryan,

 

I tracked it down to this line of code in the blackberry10 resolveLocalFileSystemURI.js file:

 

       window.requestAnimationFrame(function () {

 

window.requestAnimationFrame is null so this is failing.  Any idea why this is?

 

The device I'm testing on is on version 10.1.0.238 if that makes a difference.

Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: Cordova 3.4 / File plugin 1.0.1 - resolveLocalFileSystemURL for camera image

Thanks.

 

It appears that function wasn't introduced until 10.2. I'll update the issue accordingly.

 

You can add this to the work-around:

 

if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function (callback) { callback(); };
}

 

This was introduced recently to work around a bug in webkit which prevented multiple file system creation within a callback chain. For most use cases, this isn't a problem.

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
New Contributor
Posts: 9
Registered: ‎03-13-2014
My Device: N/A
My Carrier: N/A

Re: Cordova 3.4 / File plugin 1.0.1 - resolveLocalFileSystemURL for camera image

Thanks Bryan - one last question.

 

Is it intentional that file.toURL() returns a path with no protocol? I would have expected "file://" to be part of the result when toURL() is called and just the path when using file.fullPath is used.

 

My concern is I believe the toURL result is meant to be bindable to an images src directly without any manipulation.

Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: Cordova 3.4 / File plugin 1.0.1 - resolveLocalFileSystemURL for camera image

I agree, it should return the protocol. I will take a look. Please keep an eye on the Apache issue for updates.

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins