Filereader.readasdataurl Result Returning Format Exception When Entered In Convert.frombase64string
I'm using the following to convert an image to a base64 encoded string. On the client website in javascript: var reader = new FileReader(); reader.onloadend = function () {
Solution 1:
Okay, I have worked around this by using reader.readAsBinaryString
instead and then converting this using btoa
.
This seems to be accepted fine in Convert.FromBase64String
Solution 2:
I experienced the same issue and founds out that my complete dataurl contained not only padding characters at the end, but also padding characters in the middle of the dataurl. I used the following code to fix the base64string (but it still has a bug):
privatestaticstringgetCleanedBase64String(string base64String)
{
string tempString = base64String.Replace("_", "/").Replace("-", "+").Replace("=", "");
return tempString + newstring('=', (4 - tempString.Length % 4) % 4);
}
Post a Comment for "Filereader.readasdataurl Result Returning Format Exception When Entered In Convert.frombase64string"