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.
Web DevelopmentHTMLJavaScript

Avatar of undefined
Last Comment
Roger Alcindor

8/22/2022 - Mon
leakim971

If it's à web application, your server send the informations on the page. Why not reading/getting from there ?
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.
David Favor

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
leakim971

OK, so why not capturing with :
<input type="file" accept="image/*;capture=camera">

so you can save the picture to server with a <form />
Roger Alcindor

ASKER
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
leakim971

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

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Roger Alcindor

ASKER
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 ?
leakim971

what is server side language ? the file content is posted too, you just need to figure how to get it
Roger Alcindor

ASKER
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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Roger Alcindor

ASKER
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.