gavriel ankri

gavriel ankri

  • NA
  • 39
  • 47.6k

send image to data server

Apr 11 2015 4:31 AM
hello
 
I am using this code to send image data to server.
however it works for me only with amll png and not with jpg or bigger images.
 what is the problem ?
 
 
 
reader = new FileReader();
reader.onload = function (e) {
document.getElementById("blah").src = e.target.result;
pp = e.target.result;
}
reader.readAsDataURL(file);
fileName = (file.name).slice(-3);
}
function UploadPic() {
// generate the image data
var Pic = pp.replace(/^data:image\/(png|jpg);base64,/, "")
// Sending the image data to Server
$.ajax({
type: 'POST',
url: 'Save_Picture.aspx/UploadPic',
data: '{ "imageData" : "' + Pic + '", "imageName" : "' + fileName + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
alert("Done, Picture Uploaded.");
}
});
}
 

Answers (2)