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
New Contributor
Keab42
Posts: 5
Registered: ‎12-23-2013
My Device: Z10

Re: Cordova 3.2.0 Capture Plugin not working

[ Edited ]

I'm glad to see I'm not the only person having trouble with this.

 

I did log a couple of issues with the official Cordova JIRA last week.

 

For instance the capture plugin also fails when taking video.

 

 

**EDIT**

 

It seems as though adding:

 

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

 

 

to the config.xml file that's stored in the www folder of the Phonegap project (not the platform/blackberry/www) has got pictures working for me (albeit ignoring orientation).

 

For reference my app is built with Cordova 3.3.1 and Sencha Touch 2.3.1.

BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10

Re: Cordova 3.2.0 Capture Plugin not working

[ Edited ]

It seems that resolveLocalFilesystemURI is the issue here. Our dev teams have confirmed and log a bug report with Cordova:

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

 

By default, that method will always look inside the sandbox, where the correct implementation should be to set sandbox, then request a persistent file system, then open the file. 

 

This can be done using the WebWorks APIs directly, but not straight-up Cordova until this is fixed.

 

 

Update #1

 

Using the patched File plugin (linked above) resolved the issues with resolveLocalFileSystemURI for me. I've also gotten further with the FileTransfer API, however for some reason the FILES array on the PHP server is empty. The transfer is successfully occurring as the Bytes Sent and HTTP Status (200) are being properly reported, but the FILES array, which is needed to save the final version of the file, is empty. I'm checking with our team to see if they have any insight.

 

For reference, the takePhoto function is as follows (note that I am still manually removing the file:// prefix from the URI.

 

 

function takePhoto() {
	navigator.camera.getPicture(
		function (imageURI) {
			var image, options, ft;

			image = document.getElementById('imgTarget');
			image.src=imageURI;
			imageURI = imageURI.replace('file://', '');

			options = new FileUploadOptions();
			options.fileKey = 'file';
			options.fileName = 'upload.jpg';
			options.mimeType = 'image/jpeg';
			options.chunkedMode = true;
			options.chunkSize = 1024;
			options.params = {
				'app': 'webworks'
			};

			ft = new FileTransfer();
			ft.upload(
				imageURI,
				encodeURI('http://R9N2R9M-4243B64.rim.net/fileTransfer/upload.php'),
				function uploadSuccess(result) {
					console.log('Bytes sent: ' + result.bytesSent);
					console.log('Response code: ' + result.responseCode);
					console.log('Response: ' + result.response);
				},
				function uploadError(result) {
					console.log('Error code: ' + result.code);
					console.log('Source: ' + result.source);
					console.log('Target: ' + result.target);
					console.log('HTTP Status: ' + result.https_status);
				},
				options
			);
		},
		function (message) {
			console.log('getPicture failed because: ' + message);
		},
		{
			quality: 50,
			destinationType: Camera.DestinationType.FILE_URI
		}
	);
}

 

Update #2

 

Big than you to bryanhiggins for the help here. Short version of the solution, you will need the updated File plugin here (allows access outside of the sandbox as intended):

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

 

 

And you will also need to update XHRImplementation.js as outlined here. Basically, calling file.nativeFile.slice instead of file.slice.

 

For reference, this file was found at the following location in my Cordova project:

...\plugins\org.apache.cordova.file-transfer\www\blackberry10\XHRImplementation.js

 

With these changes, the Cordova approach we've been discussing worked.

 

Let us know if you have any questions.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Developer
jeff_sawatzky
Posts: 29
Registered: ‎04-01-2013
My Device: Z10

Re: Cordova 3.2.0 Capture Plugin not working

Any update on this?

  1. why is resolveLocalFileSystemURI failing with error code 5?
  2. why doesn't the cordova build process add the <rim:smileytongue:ermit>access_shared</rim:smileytongue:ermit> element to the config.xml when building (like how it adds other permissions that are required)?
BlackBerry Development Advisor
bryanhiggins
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3

Re: Cordova 3.2.0 Capture Plugin not working

Hi,

 

The resolveLocalFileSystemURI error has been fixed for the next Cordova and WebWorks releases.

 

You can pick it up from this branch now:

https://github.com/apache/cordova-plugin-file/tree/dev

 

access_shared is not required to read and write files from within the application sandbox, which is why it is not automatically added by the plugin.

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Developer
jeff_sawatzky
Posts: 29
Registered: ‎04-01-2013
My Device: Z10

Re: Cordova 3.2.0 Capture Plugin not working

Hi Bryan,

 

thanks for the update on the resolveLocalFileSystemURI. I will look into it and let you know my results.

 

As for the access_shared permission, it seems like the Camera plugin uses the shared location (at least when saveToPhotoAlbum is true), eg:

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

So, in order to access this file I have had to add access_shared to my global config.xml. Also, in order to do camera.getPicture from the PictureSourceType.PHOTOLIBRARY, would we not need the access_shared permission as well?

 

Or am I missing something?

New Contributor
Keab42
Posts: 5
Registered: ‎12-23-2013
My Device: Z10

Re: Cordova 3.2.0 Capture Plugin not working

Thanks.

 

Feel free to close my duplicate issue on the Cordova Jira: https://issues.apache.org/jira/browse/CB-5685

 

Any idea when we might expect the official plugin to be updated with a new point release?

BlackBerry Development Advisor
bryanhiggins
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3

Re: Cordova 3.2.0 Capture Plugin not working

I misunderstood. You're right - the capture plugin should have access_shared permission as the camera card can only write to shared areas. I've added it.

 

The plugins ship independently from Cordova releases. I expect them to be updated within the next couple weeks.

 

You can check the status here:

http://plugins.cordova.io/

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins