Link to home
Start Free TrialLog in
Avatar of Roger Alcindor
Roger Alcindor

asked on

Web client HTML5/CSS Javascript to take apicture in a web application

I am writing a Windows web application using HTML5 & CSS and java-script. I wish for the web page to respond to a button click by operating the camera on the device displaying the web page so as to autofocus and take a picture image (in jpeg format) and return the image to the server in a Get or Post web action.
I am using Embarcadero C++ builder XE10.2 to develop the application.

The device viewing the web page is an Android mobile device which is using the chrome web browser. The image returned to the web application will be subjected to optical barcode recognition and the web application will respond according to the barcode that has been decoded;

I am seeking any relevant example code or references to appropriate tutorials. I don't need any assistance with decoding the barcode image, I do need help in acquiring the image from the mobile device's camera via the web page being displayed.
Avatar of leakim971
leakim971
Flag of Guadeloupe image

If it's à web application, your server send the informations on the page. Why not reading/getting from there ?
Avatar of Roger Alcindor
Roger Alcindor

ASKER

Because the camera is on a mobile device which is a client to the web application. the web application is running on a different machine in a different location and is acting as a web server.
I'd start by scripting this.

Use Powershell or Cygwin + bash.

Start with scripting + when you figure out all the idiosyncrasies, then convert this to code.
OK, so why not capturing with :
<input type="file" accept="image/*;capture=camera">

so you can save the picture to server with a <form />
Hello leakim971,
Thanks for your comment. I'm almost there.
my HTML code is shown below. The  mobile device displays a message Choose file No file chosen.
Then I tap the "Choose file" and am prompted to choose an action (Camera, Camcorder or documents).
I choose Camera and the camera is switched on and the camera image is displayed.
I then tap the camera Icon to take a photo  and a prompt appears for either OK or Retry.
I tap the OK option and a filename ending in .jpg is shown  but no "post" action is performed.
How do I get the "post" action to be performed ?

<div id="div1">
	<form name="scanner" action="" method="post">
	<label style ="margin-top:0px; font-size:50px;"for="barcodescan">Scan Barcode</label>
		<input name="picture" type="file" id="barcodescan" accept="image/*;capture=camera">
	</form>
</div>

Open in new window


Thanks,

Roger
Try this :
<div id="div1">
	<form name="scanner" id="scannerForm"  action="" method="post">
	<label style ="margin-top:0px; font-size:50px;"for="barcodescan">Scan Barcode</label>
		<input name="picture" type="file" id="barcodescan" accept="image/*;capture=camera">
	</form>
</div>
<script>
    document.getElementById("barcodescan").onchange = function() {
          if( this.files.length != 0 ) {
                 document.getElementById("scannerForm").submit();
          }
          else {
                alert("no barcode picked, please try again!");
          }
    }
</script>

Open in new window

Excellent ! thanks very much for your help, it's really appreciated.
One last thing if you don't mind ? What gets posted is the name of the file, for example "picture=1512227382900-1699657311.jpg"
How do I get the contents of the file (the jpeg file) to be posted instead ?
what is server side language ? the file content is posted too, you just need to figure how to get it
I attach a Wire-shark capture of the TCP traffic from the remote device (IP address 192.168.1.89) to the server application (192.168.1.77) after the photo has been taken and the OK area has been tapped.
The POST package is evident but the size is nowhere near the size of a high resolution jpeg file and inspecting the Wire-shark data shows plain English text. I would say that the Jpeg image data is not being sent ?
C--Users-roger-Downloads-Screenshots.JPG
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That did the trick. Many thanks again.
the language of the web application is C++ with which I am quite proficient. I just have to manipulate the raw data (jpeg image) in the rest of the application.