In the past, I often did base64 conversion to pictures, and there was never any problem. Today, I used js to convert Canvas to Base64-bit strings
bbb is the string we get, and then I pass it to the background with ajax, like this;
Background Receiving Code:
Damn, the second sentence was reported incorrectly!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Error list
{"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. "} {"Invalid length for a Base-64 char array or string."} The first error is because, there is data:image/jpeg in the string; base64, just get rid of this thing!
This code solves the first error!!
The second mistake, I don't know what was wrong, I worked for an hour, and finally saw a few words from the foreigner forum
The length of a base64 encoded string is always a multiple of 4. If it is not a multiple of 4, then = characters are appended until it is. A query string of the form ?name=value has problems when the value contains = charaters (some of them will be dropped, I don't recall the exact behavior). You may be able to get away with appending the right number of = characters before doing the base64 decode. The translation is as follows, just take a look at it roughly
A Base64 encoded string is a multiple of 4 in length. If it is not a multiple of 4, then the = character is appended until. A query string for a table? name=value when there is a problem with value contains = features (some of them will go down, I don't remember the exact behavior). You can add the correct number = character before doing base64 decoding. Finally, add a few sentences of code, and you're done, the complete code is as follows:
|