salvo italy
salvo italy

Reputation: 193

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?

Upvotes: 0

Views: 1240

Answers (1)

gon250
gon250

Reputation: 3545

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);

Upvotes: 1

Related Questions