Click here to Skip to main content
14,300,422 members
Rate this:
Please Sign up or sign in to vote.
See more:
1. Create Capture.cshtml
2. IAction Method Capture
3. saveSnap() function not call Capture method in Camera Controller

What I have tried:

Webcam.set({
        width: 320,
        height: 240,
        image_format: 'jpeg',
        jpeg_quality: 90
    });
    Webcam.attach('#my_camera');




    function take_snapshot() {
        // take snapshot and get image data
        Webcam.snap(function (data_uri) {
            // display results in page
            document.getElementById('results').innerHTML =
                '<img id="base64image" src="' + data_uri + '"/>';
        });        
    }
    function saveSnap() {
        var base64image = document.getElementById("base64image").src;
        alert(base64image);
        Webcam.upload(base64image, '/Camera/Capture', function (code, text) {   
            alert('Save successfully');                    
        });

    }

============================
[HttpPost]
        public IActionResult Capture(EnrolmentViewModels model)
        {
            try
            {
                var files = HttpContext.Request.Form.Files;
                if (files != null)
                {
                    foreach (var file in files)
                    {
                        if (file.Length > 0)
                        {
                            // Getting Filename
                            var fileName = file.FileName;
                            // Unique filename "Guid"
                            var myUniqueFileName = Convert.ToString(Guid.NewGuid());
                            // Getting Extension
                            var fileExtension = Path.GetExtension(fileName);
                            // Concating filename + fileExtension (unique filename)
                            var newFileName = string.Concat(myUniqueFileName, fileExtension);
                            //  Generating Path to store photo 
                            var filepath = Path.Combine(_environment.WebRootPath, "CameraPhotos") + $@"\{newFileName}";

                            if (!string.IsNullOrEmpty(filepath))
                            {
                                // Storing Image in Folder
                                StoreInFolder(file, filepath);

                                EnrolmentMaster objEnrol = _enrolment.GetEnrolmentId(Convert.ToInt32(model.EnrolmentId));
                                objEnrol.PhotoPath = filepath;
                                objEnrol.ModifiedDate = DateTime.Now;
                                objEnrol.IPAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                                _enrolment.Update(objEnrol);
                                TempData["EnrolmentMessage"] = "Save image Successfully";
                            }
                        }
                    }
                }
                return View();
            }
            catch (Exception)
            {
                throw;
            }
        }

        private void StoreInFolder(IFormFile file, string fileName)
        {
            using (FileStream fs = System.IO.File.Create(fileName))
            {
                file.CopyTo(fs);
                fs.Flush();
            }
        }
    }
Posted
Updated 11-Sep-19 2:15am
v3
Comments
Richard MacCutchan 11-Sep-19 7:10am
   
And the question is ... ?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100