I have spent all day looking through all the articles and attemted almost every fix i came across with no luck, I know there are tons of these Base64 issues but not one post was able to help me. So here goes nothing...
This is my JS with image blob, Blob is being sent from a websocket connection.
var reader = new FileReader();
//// Closure to capture the file information.
reader.onload = (function (e) {
return function (e) {
var xhr = new XMLHttpRequest();
xhr.open('POST', '/Home/GetLicScan', true);
xhr.onload = function (e) {
var result = e.target.result;
};
xhr.send('{"blob":"' + e.target.result + '"}');
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
This is my Controller
public JsonResult GetLicScan()
{
int counter = 0;
counter++;
byte[] data = Convert.FromBase64String(Request.ToString());
System.IO.File.WriteAllBytes(@"C:\Test" + counter + ".png", data);
return Json("success");
}
Some guidance on how to get rid of error and save blog to image.png/jpg would be highly appreciated.
Here is the VS Exception, I'm sure some are sick of reading it... System.FormatException occurred HResult=0x80131537 Message=The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
I figured it out!! Thanks to everyone who attempted to help.
the issue is "Request.ToString()", I needed to use Stream and StreamReader.
User contributions licensed under CC BY-SA 3.0