I am talking about uploading the image file to a textbox set as varbinary. Please HELP! Please how do I convert the image file to byte array so I can store that in the database. Also how do I render the image from the database unto my view for visualisation?
Here is the code and the textbox html code:
function displayFileName(fileInput) { // Get the value (path/filename) from the file input element var fullPath = fileInput.value;
// Use JavaScript to get just the filename without the "C:\fakepath\" prefix var fileName = fullPath.split('\\').pop();
// Find the target textbox and set its value to the filename document.getElementById("WorkerImage").value = fileName; }
<form asp-action="WorkerIdentification"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="form-group"> <label asp-for="FirstName" class="control-label"></label> <input asp-for="FirstName" class="form-control" name="FirstName" /> <span asp-validation-for="FirstName" class="text-danger"></span> </div> <div class="form-group"> <label asp-for="LastName" class="control-label"></label> <input asp-for="LastName" class="form-control" name="LastName" /> <span asp-validation-for="LastName" class="text-danger"></span> </div> <div class="form-group"> <label asp-for="WorkerImage" class="control-label"></label> <input asp-for="WorkerImage" class="form-control" id="WorkerImage" /> <span asp-validation-for="WorkerImage" class="text-danger"></span> </div><br /> <input type="file" id="imageInput" accept="image/*" onchange="displayFileName(this);" />
<div class="form-group"> <input type="submit" value="Reposit" class="btn btn-primary" /> </div>