简体   繁体   中英

send image from javascript to C#

I have a web application C#/HTML and I must pass an image from js --> C#. The command I use is canvas.toDataURL('image/png') but the system got in crash. I use IE10.

Is there any suggest?? Thanks...

[UPDATE] Scuse me..I have a setTimeout to delay the call.When timer elapsed, the error is

Uncaught TypeError: undefined is not a function

It seams like a variable visibility. Is it possible?

First you need add an input file:

<form id="submitfile" action="youraction" method="post" enctype="multipart/form-data">
  <input type="file" id="filetoup" name="file" accept="image/*" >

then you should use ajax:

$('#submitfile').ajaxForm({
complete: function(xhr) {
    alert("Upload complete");   
} 
}); 

Also you can use the way you are using

var canvasData = canvas.toDataURL("image/png");
var ajax = new XMLHttpRequest();
ajax.open("POST",'controller/action',false);
ajax.setRequestHeader('Content-Type', 'application/upload');
ajax.send(canvasData);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM