Good day!
I have a code where a user clicks on a button, the modal pops up with a webcam.js in it. User will take a snapshot photo from webcam that will then be saved to database. The problem is I don't know how to save it to database. From what I have seen from most of the forums, they save the Image path
to the database but what I want is to save the Image itself to the database.
MODEL
public partial class tbl_Picture
{
public string picture_id { get; set; }
public string operator_id { get; set; }
public byte[] picture { get; set; }
}
CONTROLLER
[HttpPost]
public ActionResult Franchise()
{
return View();
}
VIEW
<td>
<a class="btn btn-warning open-camera" data-toggle="modal" data-id="@item.franchise_id" href="#myModal3">
Open Camera<span class="glyphicon glyphicon-plus-sign"></span>
</a>
</td>
MODAL
@using (Html.BeginForm("Franchise", "Application", FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="modal-body">
<div class="row">
<input type="text" name="franid" id="franid" value="" class="hidden" />
<div id="my_camera" class="col-lg-6"></div>
<div id="results" class="col-lg-6">Your captured image will appear here...</div>
</div>
<form>
<input type=button value="Take Snapshot" onClick="take_snapshot()">
</form>
</div>
<div class="modal-footer">
<center>
<button class="btn btn-success" type="submit">Submit</button>
<button class="btn" type="button" data-dismiss="modal">Close</button>
</center>
</div>
}
</div>
SCRIPT
<script language="JavaScript">
Webcam.set({
width: 320,
height: 240,
image_format: 'jpeg',
jpeg_quality: 90
});
Webcam.attach( '#my_camera' );
</script>
<script language="JavaScript">
function take_snapshot() {
Webcam.snap( function(data_uri) {
document.getElementById('results').innerHTML =
'<img id="base64image" src="' + data_uri + '"/>';
} );
}
</script>
I tried doing what was in this forum but I can't understand how it will save to my database. So I tried reverting back to this code and search for more ideas online.
Thanks in advance!