save images Scanner from browser in database using mvc5
hi guys I am trying to Save the Images I Scanned from the Scanner In the Database the images It show up in the Browser but i don't know how to save it in database here in my code
this is a JavaScript code
<script type="text/javascript">
var selDiv = "";
var storedFiles = ;
$(document).ready(function () {
selDiv = $("#selectedFiles");
$("body").on("click", ".selFile", editFiles);
});
var start = function () {
var i = 0;
var wsImpl = window.WebSocket || window.MozWebSocket;
window.ws = new wsImpl('ws://localhost:8181/');
ws.onmessage = function (e) {
if (typeof e.data === "string") {
//IF Received Data is String
}
else if (e.data instanceof ArrayBuffer) {
//IF Received Data is ArrayBuffer
}
else if (e.data instanceof Blob) {
i++;
var f = e.data;
f.name = "File" + i;
storedFiles.push(f);
var reader = new FileReader();
reader.onload = function (e) {
var html = "<div class="col-sm-2 text-center" style="border: 1px solid black; margin-left: 2px;"><img height="200px" width="200px" src="" + e.target.result + "" data-file='" + f.name + "' class='selFile' title='Click to remove'><br/>" + i + "</div>";
selDiv.append(html);
}
reader.readAsDataURL(f);
}
};
ws.onopen = function () {
//Do whatever u want when connected succesfully
};
ws.onclose = function () {
$('.dalert').modal('show');
};
}
window.onload = start;
function scanImage() {
ws.send("1100");
};
function editFiles(e) {
var file = $(this).data("file");
for (var i = 0; i < storedFiles.length; i++) {
if (storedFiles[i].name === file) {
$('.scandetail').modal('show');
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = new Image();
img.src = window.URL.createObjectURL(storedFiles[i]);
img.onload = function () {
c.width = img.width ;
c.height = img.height;
ctx.drawImage(img, 0, 0, img.width, img.height);
}
break;
}
}
};
</script>
****here is my create****
<button type="button" onclick="scanImage();" class="btn btn-primary btn-lg">Scan</buton>
<div id="selectedFiles" class="row" style="padding:3px;overflow-x: scroll;display: flex;"></div>
<div class="modal fade scandetail" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div style="max-height:1200px;overflow:scroll;">
<canvas id="myCanvas"></canvas>
</div>
</div>
</div>
</div>
and here is my Controller
public async Task<ActionResult> Create(Inbox model)
{
var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
if (ModelState.IsValid)
{
model.User = currentUser;
List<FileDetail> fileDetails = new List<FileDetail>();
for (int i = 0; i < Request.Files.Count; i++)
{
var file = Request.Files[i];
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
FileDetail fileDetail = new FileDetail()
{
FileName = fileName,
Extension = Path.GetExtension(fileName),
Id = Guid.NewGuid()
};
fileDetails.Add(fileDetail);
var path = Path.Combine(Server.MapPath("~/FilesAPP/"), fileDetail.Id + fileDetail.Extension);
file.SaveAs(path);
}
}
model.FileDetails = fileDetails;
db.Inboxs.Add(model);
db.SaveChanges();
string url = Url.Action("List");
return Json(new { success = true, url = url });
}
return View(model);
}
how can I Save those Images i scanned in browser in to the database guys
c# asp.net razor asp.net-mvc-5 asp.net-mvc-5.2
add a comment |
hi guys I am trying to Save the Images I Scanned from the Scanner In the Database the images It show up in the Browser but i don't know how to save it in database here in my code
this is a JavaScript code
<script type="text/javascript">
var selDiv = "";
var storedFiles = ;
$(document).ready(function () {
selDiv = $("#selectedFiles");
$("body").on("click", ".selFile", editFiles);
});
var start = function () {
var i = 0;
var wsImpl = window.WebSocket || window.MozWebSocket;
window.ws = new wsImpl('ws://localhost:8181/');
ws.onmessage = function (e) {
if (typeof e.data === "string") {
//IF Received Data is String
}
else if (e.data instanceof ArrayBuffer) {
//IF Received Data is ArrayBuffer
}
else if (e.data instanceof Blob) {
i++;
var f = e.data;
f.name = "File" + i;
storedFiles.push(f);
var reader = new FileReader();
reader.onload = function (e) {
var html = "<div class="col-sm-2 text-center" style="border: 1px solid black; margin-left: 2px;"><img height="200px" width="200px" src="" + e.target.result + "" data-file='" + f.name + "' class='selFile' title='Click to remove'><br/>" + i + "</div>";
selDiv.append(html);
}
reader.readAsDataURL(f);
}
};
ws.onopen = function () {
//Do whatever u want when connected succesfully
};
ws.onclose = function () {
$('.dalert').modal('show');
};
}
window.onload = start;
function scanImage() {
ws.send("1100");
};
function editFiles(e) {
var file = $(this).data("file");
for (var i = 0; i < storedFiles.length; i++) {
if (storedFiles[i].name === file) {
$('.scandetail').modal('show');
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = new Image();
img.src = window.URL.createObjectURL(storedFiles[i]);
img.onload = function () {
c.width = img.width ;
c.height = img.height;
ctx.drawImage(img, 0, 0, img.width, img.height);
}
break;
}
}
};
</script>
****here is my create****
<button type="button" onclick="scanImage();" class="btn btn-primary btn-lg">Scan</buton>
<div id="selectedFiles" class="row" style="padding:3px;overflow-x: scroll;display: flex;"></div>
<div class="modal fade scandetail" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div style="max-height:1200px;overflow:scroll;">
<canvas id="myCanvas"></canvas>
</div>
</div>
</div>
</div>
and here is my Controller
public async Task<ActionResult> Create(Inbox model)
{
var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
if (ModelState.IsValid)
{
model.User = currentUser;
List<FileDetail> fileDetails = new List<FileDetail>();
for (int i = 0; i < Request.Files.Count; i++)
{
var file = Request.Files[i];
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
FileDetail fileDetail = new FileDetail()
{
FileName = fileName,
Extension = Path.GetExtension(fileName),
Id = Guid.NewGuid()
};
fileDetails.Add(fileDetail);
var path = Path.Combine(Server.MapPath("~/FilesAPP/"), fileDetail.Id + fileDetail.Extension);
file.SaveAs(path);
}
}
model.FileDetails = fileDetails;
db.Inboxs.Add(model);
db.SaveChanges();
string url = Url.Action("List");
return Json(new { success = true, url = url });
}
return View(model);
}
how can I Save those Images i scanned in browser in to the database guys
c# asp.net razor asp.net-mvc-5 asp.net-mvc-5.2
add a comment |
hi guys I am trying to Save the Images I Scanned from the Scanner In the Database the images It show up in the Browser but i don't know how to save it in database here in my code
this is a JavaScript code
<script type="text/javascript">
var selDiv = "";
var storedFiles = ;
$(document).ready(function () {
selDiv = $("#selectedFiles");
$("body").on("click", ".selFile", editFiles);
});
var start = function () {
var i = 0;
var wsImpl = window.WebSocket || window.MozWebSocket;
window.ws = new wsImpl('ws://localhost:8181/');
ws.onmessage = function (e) {
if (typeof e.data === "string") {
//IF Received Data is String
}
else if (e.data instanceof ArrayBuffer) {
//IF Received Data is ArrayBuffer
}
else if (e.data instanceof Blob) {
i++;
var f = e.data;
f.name = "File" + i;
storedFiles.push(f);
var reader = new FileReader();
reader.onload = function (e) {
var html = "<div class="col-sm-2 text-center" style="border: 1px solid black; margin-left: 2px;"><img height="200px" width="200px" src="" + e.target.result + "" data-file='" + f.name + "' class='selFile' title='Click to remove'><br/>" + i + "</div>";
selDiv.append(html);
}
reader.readAsDataURL(f);
}
};
ws.onopen = function () {
//Do whatever u want when connected succesfully
};
ws.onclose = function () {
$('.dalert').modal('show');
};
}
window.onload = start;
function scanImage() {
ws.send("1100");
};
function editFiles(e) {
var file = $(this).data("file");
for (var i = 0; i < storedFiles.length; i++) {
if (storedFiles[i].name === file) {
$('.scandetail').modal('show');
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = new Image();
img.src = window.URL.createObjectURL(storedFiles[i]);
img.onload = function () {
c.width = img.width ;
c.height = img.height;
ctx.drawImage(img, 0, 0, img.width, img.height);
}
break;
}
}
};
</script>
****here is my create****
<button type="button" onclick="scanImage();" class="btn btn-primary btn-lg">Scan</buton>
<div id="selectedFiles" class="row" style="padding:3px;overflow-x: scroll;display: flex;"></div>
<div class="modal fade scandetail" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div style="max-height:1200px;overflow:scroll;">
<canvas id="myCanvas"></canvas>
</div>
</div>
</div>
</div>
and here is my Controller
public async Task<ActionResult> Create(Inbox model)
{
var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
if (ModelState.IsValid)
{
model.User = currentUser;
List<FileDetail> fileDetails = new List<FileDetail>();
for (int i = 0; i < Request.Files.Count; i++)
{
var file = Request.Files[i];
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
FileDetail fileDetail = new FileDetail()
{
FileName = fileName,
Extension = Path.GetExtension(fileName),
Id = Guid.NewGuid()
};
fileDetails.Add(fileDetail);
var path = Path.Combine(Server.MapPath("~/FilesAPP/"), fileDetail.Id + fileDetail.Extension);
file.SaveAs(path);
}
}
model.FileDetails = fileDetails;
db.Inboxs.Add(model);
db.SaveChanges();
string url = Url.Action("List");
return Json(new { success = true, url = url });
}
return View(model);
}
how can I Save those Images i scanned in browser in to the database guys
c# asp.net razor asp.net-mvc-5 asp.net-mvc-5.2
hi guys I am trying to Save the Images I Scanned from the Scanner In the Database the images It show up in the Browser but i don't know how to save it in database here in my code
this is a JavaScript code
<script type="text/javascript">
var selDiv = "";
var storedFiles = ;
$(document).ready(function () {
selDiv = $("#selectedFiles");
$("body").on("click", ".selFile", editFiles);
});
var start = function () {
var i = 0;
var wsImpl = window.WebSocket || window.MozWebSocket;
window.ws = new wsImpl('ws://localhost:8181/');
ws.onmessage = function (e) {
if (typeof e.data === "string") {
//IF Received Data is String
}
else if (e.data instanceof ArrayBuffer) {
//IF Received Data is ArrayBuffer
}
else if (e.data instanceof Blob) {
i++;
var f = e.data;
f.name = "File" + i;
storedFiles.push(f);
var reader = new FileReader();
reader.onload = function (e) {
var html = "<div class="col-sm-2 text-center" style="border: 1px solid black; margin-left: 2px;"><img height="200px" width="200px" src="" + e.target.result + "" data-file='" + f.name + "' class='selFile' title='Click to remove'><br/>" + i + "</div>";
selDiv.append(html);
}
reader.readAsDataURL(f);
}
};
ws.onopen = function () {
//Do whatever u want when connected succesfully
};
ws.onclose = function () {
$('.dalert').modal('show');
};
}
window.onload = start;
function scanImage() {
ws.send("1100");
};
function editFiles(e) {
var file = $(this).data("file");
for (var i = 0; i < storedFiles.length; i++) {
if (storedFiles[i].name === file) {
$('.scandetail').modal('show');
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = new Image();
img.src = window.URL.createObjectURL(storedFiles[i]);
img.onload = function () {
c.width = img.width ;
c.height = img.height;
ctx.drawImage(img, 0, 0, img.width, img.height);
}
break;
}
}
};
</script>
****here is my create****
<button type="button" onclick="scanImage();" class="btn btn-primary btn-lg">Scan</buton>
<div id="selectedFiles" class="row" style="padding:3px;overflow-x: scroll;display: flex;"></div>
<div class="modal fade scandetail" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div style="max-height:1200px;overflow:scroll;">
<canvas id="myCanvas"></canvas>
</div>
</div>
</div>
</div>
and here is my Controller
public async Task<ActionResult> Create(Inbox model)
{
var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
if (ModelState.IsValid)
{
model.User = currentUser;
List<FileDetail> fileDetails = new List<FileDetail>();
for (int i = 0; i < Request.Files.Count; i++)
{
var file = Request.Files[i];
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
FileDetail fileDetail = new FileDetail()
{
FileName = fileName,
Extension = Path.GetExtension(fileName),
Id = Guid.NewGuid()
};
fileDetails.Add(fileDetail);
var path = Path.Combine(Server.MapPath("~/FilesAPP/"), fileDetail.Id + fileDetail.Extension);
file.SaveAs(path);
}
}
model.FileDetails = fileDetails;
db.Inboxs.Add(model);
db.SaveChanges();
string url = Url.Action("List");
return Json(new { success = true, url = url });
}
return View(model);
}
how can I Save those Images i scanned in browser in to the database guys
c# asp.net razor asp.net-mvc-5 asp.net-mvc-5.2
c# asp.net razor asp.net-mvc-5 asp.net-mvc-5.2
edited Nov 21 '18 at 21:03
jmal hassn
asked Nov 21 '18 at 13:34
jmal hassnjmal hassn
86
86
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413240%2fsave-images-scanner-from-browser-in-database-using-mvc5%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413240%2fsave-images-scanner-from-browser-in-database-using-mvc5%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown