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
Contributor
Posts: 22
Registered: ‎01-20-2011
My Device: Bold 9650
My Carrier: Verizon

Returning the file after having taken a picture

Hi,

I'm having some trouble returning the image file after having taken a picture using the new Camera API.

 

This code works fine:

             function takePicture() {
             try {
            blackberry.media.camera.takePicture(successCB, closedCB, errorCB);
            } catch(e) {
              alert("Error in supported: " + e);
            }
          }

          function successCB(filePath) {  
              document.getElementById("path").innerHTML = filePath;

   
            alert("Succeed: " + filePath);
         }

          function closedCB() {
           // alert("Camera closed event");
          }

          function errorCB(e) {
            alert("Error occured: " + e);
          }

 

and I see the path to the image just captured:

<div id="path"></div>

 

but I need the file within my form:

<input name="userfile" type="file" />

I can change the name of the field from "userfile" to something else, if it is accessible under another name.

I don't want the user to have to browse to the picture they just took, I want it to automatically get populated in my form.

Thanks

Contributor
Posts: 41
Registered: ‎07-21-2011
My Device: Superberry
My Carrier: Rogers

Re: Returning the file after having taken a picture

It's not possible to set the value of a file input in HTML for security reasons. It works this way for all browsers, big and small.

Do you want to upload your picture to a server?
----------------------------------------------------------------------------------------------
I kode for cudos! Or was it the other way around?
Contributor
Posts: 22
Registered: ‎01-20-2011
My Device: Bold 9650
My Carrier: Verizon

Re: Returning the file after having taken a picture

Yes, the Form data is posted to a php script on my server which stores the data in SQL and copies the image to the hard drive of the server.  Any suggestions?

Contributor
Posts: 22
Registered: ‎01-20-2011
My Device: Bold 9650
My Carrier: Verizon

Re: Returning the file after having taken a picture

One other thing, which will make a difference for submission.  My webworks app will be used almost exclusively when the user has no internet access.  So, my form's submit button will have to store the data and picture in SQLite until the user regains their internet access and is then able to submit the data and picture to the server.  I've got the form (except for the image) working while the user has internet access right now (as a first step) and am starting to work on the code for storing locally using SQLite database.

 

Contributor
Posts: 41
Registered: ‎07-21-2011
My Device: Superberry
My Carrier: Rogers

Re: Returning the file after having taken a picture

Unfortunately there's no coverage change listener, but you can easily write an extension to do one. 

 

I would approach your scenario in the following way:

1) Put a button on the form that submits the data. 

2) Create a coverage change listener that triggers a callback when you're out of coverage. In the callback change the behaviour of the submit button to either post the file through an AJAX request or send it to the DB.

3) When the device comes into coverage, post anything in the DB through AJAX to your server.

----------------------------------------------------------------------------------------------
I kode for cudos! Or was it the other way around?
Retired
Posts: 518
Registered: ‎07-18-2011
My Device: Bold
My Carrier: Rogers

Re: Returning the file after having taken a picture

Actually there is a coverage change listener built right into WebWorks. Check out the System Events API - http://www.blackberry.com/developers/docs/webworks/api/blackberry.system.event.html#.onCoverageChang...



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)