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
Regular Contributor
ingybing
Posts: 65
Registered: ‎01-21-2011
My Device: Not Specified
Accepted Solution

Linking to pictures taken with the camera.

Hi,

 

I'm currently working with the simulator and have taken an picture with the camera which i want to show in the widget or better still access it to try and send it to a web service. 

 

If i do the following in java script :

 

var path = "file:///store/home/user/pictures/IMG00042-20110121-1222.jpg";

alert(blackberry.io.file.exists(path));

 

it results in an alert reading "true" as i would expect so it can definately see the file at this path. However when i try and set a local image tags SRC value to the above path i just get a broken image showing. If i try to read the file using:

 

blackberry.io.file.readFile(path, handleOpenedFile);

 

 

function handleOpenedFile(fullPath, blobData) {

 

 alert("file opened was: " + fullPath + " which contained " + blobData.length + " bytes.");

}

 

the resulting WidgetBlob value appears to be empty (the length property etc all come back as 'UNDEFINED'.

 

Am i missing somewhere here, can anyone tell me what I am doing wrong.

 

Thanks :smileysurprised:)

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Linking to pictures taken with the camera.

If you are wanting to use the image in an <img> tag you will have to white list the file origin in your config.xml file:

 

 

<access uri="file:///store/home/user/pictures/" />

 

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Developer
jtyberg
Posts: 124
Registered: ‎09-06-2010
My Device: Not Specified

Re: Linking to pictures taken with the camera.

PhoneGap has a complete example of what you're trying to do, including upload to server.

 

It even provides a JavaScript API, so all you have to do to invoke the camera, get the file path, and display the image is:

 

 

    function onCapturePhotoURISuccess(imageURI) {
if (imageURI != null) {
// Show the captured photo
var smallImage = document.getElementById('cameraImage');
smallImage.src=imageURI;
}
}

function capturePhotoURI() {
navigator.camera.getPicture(onCapturePhotoURISuccess, fail,
{ destinationType: Camera.DestinationType.FILE_URI, quality: 50 });
}

 

If nothing else, you can look at the source code to see how it's done. 

 

 

 

 

 

Please use plain text.
Regular Contributor
ingybing
Posts: 65
Registered: ‎01-21-2011
My Device: Not Specified

Re: Linking to pictures taken with the camera.

Thanks for that people :smileyhappy: I've been able to do it in the Java extension but still can't get the WebWorks API bit work (blackberry.io.file.readFile). I just end up with an empty blob :-S. 

Please use plain text.