IBM Worklight 6.0 - Cordova camera simulation in the Mobile Browser Simulator doesn't work

1.2k Views Asked by At

My camera code was working fine in WL 5.0.6 and the mobile browser simulator would correctly display the image. Now I moved to WL 6.0 andI get the following error when using the preview in the Mobile Browser Simulator and using the Cordova camera simulation to get a fake picture.

I am using Chrome for the preview.

Not allowed to load local resource: file:///C:/Users/Administrator/cordova/internal/sim/camera/camera1_m.jpg wljq.js:2374

The code is similar to this

navigator.camera.getPicture(onSuccess, onFail, { quality: 50, 
destinationType: Camera.DestinationType.FILE_URI }); 

Note that if I use the DATA_URL, it seems OK with the mobile browser simulator. Just the FILE_URI doesn't seem to be working with the mobile browser simulator.

2

There are 2 best solutions below

0
On

The Worklight 6.0 Mobile Browser Simulator supports Cordova 2.6 APIs. For navigator.camera.getPicture the following destination types can be used in WL 6.0:

Camera.DestinationType = {
DATA_URL : 0,       // Return image as base64 encoded string  
FILE_URI : 1,       // Return image file URI  
NATIVE_URI : 2      // Return image native URI (eg. assets-library:// on iOS or   content:// on Android)
}; 

Example:

navigator.camera.getPicture(
        function(data) {            
document.getElementById('camera_status').innerHTML = "Success: picture  located at " +     data;

 var img = document.getElementById('camera_image');
                img.style.display = "none";
        },
        function(e) {
            console.log("Error getting picture: " + e);
            document.getElementById('camera_status').innerHTML = "Error getting picture.";
        },
        { quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.SAVEDPHOTOALBUM, encodingType: fileType});

Try clearing your browser cache and then be sure to accept the applet permission dialogue on Mobile Browser Simulator startup. Also make sure that your file permissions will allow transfer from the C:/Users//cordova/internal/sim/camera/ folder as that is where the applet stores the camera sim image content.

Cordova 2.6 Camera API reference: http://docs.phonegap.com/en/2.6.0/cordova_camera_camera.md.html

1
On

Funny, that there is already a troubleshooting document for your problem.

http://www-01.ibm.com/support/docview.wss?uid=swg21614861

It looks like DATA_URL didnt work in WLv5, while (if you are right) FILE_URI is not working since WLv6.