How would I go about debugging what's wrong with a string that I believe is in Base64 format, but which in VB using the below line of code
Dim theImage As Drawing.Image = imageUtils.Base64ToImage(teststring)
throws the following exception?
{"Base64ToImage(): 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. "}
The test string itself is far too long to paste here; I tried but reached (a lot) over the character limit. I've tried a few online conversion tools and it doesn't seem to work there either. At first I thought I was passing the string wrong from my ajax call to the web method VB code behind...but I've tried hard-coding my string into the function as well with the same failure. So, I'm convinced the string itself is bad data.
It looks like:
Dim teststring = "dataImage/ png;base64,
iVBORw0KGgoAAAANSUhEUgAAB4AAAAQ4CAYAAADo08FDAAAgAElEQVR4Xuy9268sWbbe9UVE3i /
rvte + V....K/1Tx5/8A736wVclDQN4AAAAASUVORK5CYII="
But I also tried removing the "dataImage" part and using
Dim teststring =
"iVBORw0KGgoAAAANSUhEUgAAB4AAAAQ4CAYAAADo08FDAAAgAElEQVR4Xuy9268sWbbe9UVE3i /
rvte + V....K/1Tx5/8A736wVclDQN4AAAAASUVORK5CYII="
And it doesn't make a difference.
I am getting this string in javascript using this function:
btnFreeze.onclick = video.onclick = function (e) {
e.preventDefault();
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
canvas.getContext('2d').drawImage(video, 0, 0);
alert("got here");
$hfLicenseScreenshot.val(canvas.toDataURL());
$img.css("background-image", "url(" + $hfLicenseScreenshot.val() + ")");
$("#hiddenTextbox").val($hfLicenseScreenshot.val());
//$("#save").show();
return false;
};
...where ultimately the string is from
canvas.toDataURL()
and about halfway through that function there is a hidden field called $hfLicenseScreenshot, from which I am saving the value into a "hidden" textbox (I dont know why my variable was getting lost, I know it's redundant but that's why I saved the value to a textbox called hiddentextbox. I get the sstring from hiddentextbox later, like:
$("#hiddenTextbox").val().toString();
So, I have no idea how to go about debugging this image base 64 string. I've tried different images taken from my webcam and it's just not working with any of them. Any ideas?
...I don't know if it's been serialized or not, since I think the JSON stringify method is supposed to do that. I might be confused there.
...Here is my ajax call:
$.ajax({
type: "POST",
url: "/BackCode/FirstPage.aspx/SaveData",
data: JSON.stringify({ currentData: currentData, str: makeblob(str) }),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
currentData: currentData,
success: function (resp) {
resp = resp.d;
if (resp.success) {
if (typeof callback === "function")
callback.apply(this, [resp]);
load();
} else {
$.statusMessage(resp.statusMessage, "red");
}
},
error: function (jsonObject, textStatus, errorThrown) {
$.statusMessage(errorThrown, "red");
}
});
I have also been having issues with this, and it goes into the last error function a lot:
$.statusMessage(errorThrown, "red");
So I don't know whether I'm passing it correctly either.