Hello,
I'm trying to save path/name of image captured by webcam in database
public string ProcessaUploadedFile(VisitorViewModel model)
{
// Fetch the captured file in IFormFile.
IFormFile file = Request.Form.Files[0];
string fileName = DateTime.Now.ToString("dd-MM-yy hh-mm-ss");
// Setting file Path.
string filePath = string.Format(Path.Combine(webHostEnvironment.WebRootPath, "Uploads/{0}.jpg"), fileName);
using (FileStream stream = new FileStream(filePath, FileMode.Create))
{
file.CopyTo(stream);
}
// Code for inserting data in database.
string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "Uploads");
uniqueFileName = Guid.NewGuid().ToString() + "_" + model.VisitanteFoto.FileName;
return fileName;
}
<div class="form-group">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th align="center"><u>Live Camera</u></th>
<th align="center"><u>Captured Picture</u></th>
</tr>
<tr>
<td><div id="webcam"></div></td>
<td><img id="imgCapture" /></td>
</tr>
<tr>
<td align="center">
<input type="button" id="btnCapture" value="Capture" />
</td>
<td align="center">
</td>
</tr>
</table>
</div>
<script type="text/javascript">
$(function () {
Webcam.set({
width: 320,
height: 240,
image_format: 'jpeg',
jpeg_quality: 90
});
Webcam.attach('#webcam');
$("#btnCapture").click(function () {
Webcam.snap(function (data_uri) {
$("#imgCapture")[0].src = data_uri;
Webcam.upload(data_uri, 'Visitantes/ProcessaUploadedFile', function (code, text) {
alert('Photo Captured')
});
});
});
});
</script>