Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am working on a application where users can capture their photo through webcam. after capturing , data-uri (base64 string) saved in database table. i am binding the data-uri to the image control.and the captured image showing in the image control.

i am using the asp hidden field control in javascript to get the data uri , after click on the capture button, the data-uri value (base64 string) is saving in database table. (image is also showing in the asp image control)

in local machine , it is working fine. (data uri is saving in database table).
but when upload on server, it is not working . after click on capture button, the hidden field value is coming blank. (the hidden field contains the data-uri(base64 string)).

base64string:data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAFeCAYAAABzUe0CAAAgAElEQVR4XlS9WY+lWXaetyNOnBhzqKyseeyhqieSTYmSKdOWJUgCbfjCF7YF+BcZ9oVlg5BpyxQMkWqRIiTbIgTSgAATkKAby7IsDi2JbLJpqtnNrq7qqqwcYjwnIvw+z7u/LDqrozPjnG/Ye+211rumvfbOL/7d//H29nYzdnZuxhi7Y+d2Z4yb23



how to get the hidden field value on button click ? or how to assign the hidden field value in session object in javascript. so that i can get the data-uri from the session object.

please help ..

What I have tried:

JavaScript
<asp:HiddenField ID="hdnVal" runat="server"  EnableViewState="true"  />

<script type="text/javascript" src="css/webcam.min.js"></script>
	
	<!-- Configure a few settings and attach camera -->
	<script language="JavaScript" type="text/javascript" >
	    Webcam.set({
	        width: 320,
	        height: 240,
	        dest_width: 500,
	        dest_height: 350,
	        image_format: 'png',
	        jpeg_quality: 90
	    });
	    Webcam.attach('#my_camera');





	    function take_snapshot() {
	        // take snapshot and get image data
	        var val = document.getElementById('<%=hdnVal.ClientID %>');
	        Webcam.snap(function (data_uri) {
	            var data = data_uri.toString();
	            val.value = data_uri.toString();
	            alert(val.value.toString());
	            document.getElementById('<%=hdnVal.ClientID %>').innerText = data_uri;
	        });
	    }
	
	
	</script>



Capture Button click event code :

VB
img.ImageUrl = hdnVal.Value.ToString()
img.Visible = True

Try
    con.Open()
    Dim cmd As New SqlCommand()
    cmd.CommandText = "spAddImages"
    cmd.CommandType = Data.CommandType.StoredProcedure
    cmd.Connection = con
    cmd.Parameters.Add("@val", Data.SqlDbType.NVarChar).Value = hdnVal.Value.ToString()

    cmd.ExecuteNonQuery()
    con.Close()
Catch ex As Exception

End Try
Posted
Updated 4-Apr-17 23:50pm
Comments
F-ES Sitecore 5-Apr-17 7:25am    
If you inspect the hidden field using the browser's dev tools does it have a value or is it empty? The problem might not be reading the hidden field but the fact that the field is empty. We don't know what your js library is doing to capture the webcam image but if it is using server-side code to grab the image then it will only work locally as the client and server are the same machine, but when deployed the server is its own machine that doesn't have a webcam attached.
Mahesh Pattnayak 6-Apr-17 4:15am    
The webcam is working in firefox and IE. but in chrome higher version, it is not working..

1 solution

try
function take_snapshot() {
     Webcam.snap(function (data_uri) {
         document.getElementById('<%=hdnVal.ClientID %>').value = data_uri.toString();
     });
     }
 
Share this answer
 
v2
Comments
Mahesh Pattnayak 5-Apr-17 6:03am    
No sir, it is working in local machine but in server , it is coming blank. i have used the alert message to show the value , but it is coming blank.
Karthik_Mahalingam 5-Apr-17 6:04am    
check for any errors in chrome console window

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900