I'm facing an issue where a base64 string I send through ajax to an aspx page with C# code behind always arrives empty. Despite other form fields posting successfully, this particular string is not making it through.
The base64 string in question appears as follows:
QmFzZSA2NCDigJQgTW96aWxsYSBEZXZlbG9wZXIgTmV0d29yaw==
The method responsible for sending the string to the C# code behind reads:
string signature = Request.Form.Get("newsig");
var pdfContents = PDFHelper.GeneratePDF(pdfPath, formFieldMap, signature);
Within the C# code, the handling of the base64 string occurs like so:
string base64image = sig;
// Convert base64string to byte array
var newbytes = Convert.FromBase64String(base64image);
I suspect that the length of the base64 string might be causing issues at times. Is there a more efficient way to manage base64 strings in C#?
UPDATE: Below is an excerpt from my ajax post method:
var localbase64string = localStorage["signature"];
var b64 = localbase64string.replace(/^data:image\/(png|jpg);base64,/, "");
var formData = new FormData($(this)[0]);
formData.append( 'newsig', b64);
var sendPost = 'http://xxx.xx/this.aspx';
$.ajax({
type: 'POST',
data: formData,
processData: false,
contentType: false,
timeout: 50000,
url: sendPost,
success: function(data){
alert('Sent!');
window.location.href = './../mainmenu.html';
}, error:function (){
alert("something went wrong!");
}
});