javascript - Can't Send Base64 string To C# via AJAX -


i sending base64 string thru ajax aspx page c# code behind. string never makes c#. comes out empty.

the ajax being sent in post request , other form fields post fine.

my string looks like: qmfzzsa2ncdigjqgtw96awxsysbezxzlbg9wzxigtmv0d29yaw==

the method sends string c# code behind is:

string signature = request.form.get("newsig"); var pdfcontents = pdfhelper.generatepdf(pdfpath, formfieldmap, signature); 

the code behind:

string base64image = sig; //  convert base64string bytes array var newbytes = convert.frombase64string(base64image); 

sometimes base64 string long - issue? there better way of handling base64 strings in c#?

update: 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!");         }      }); 

another way check content you're sending use request.content.readasstringasync().result in c# receiving method.

here's example put quick:

c#:

public ihttpactionresult postb64test(string one, string two)     {         string b64 = request.content.readasstringasync().result;                     return ok();     } 

js:

// here's example url. i'm adding base64 string post body, // , other parameters in query string.   var url = '/api/xxx/b64/?one=' +1 +'&two=' +2 +'';   var b64 = ""; // base64 string e.g., "9j/4aaqskzjrgabag..."  $http.post(url, { b64: b64 }); 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -