This article is a mirror article of machine translation, please click here to jump to the original article.

View: 34628|Reply: 2

[Source] Damn, the base64 string to image conversion is finally done

[Copy link]
Posted on 1/28/2016 5:22:02 PM | | | |


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:







Previous:Recommend a JS image cropping plugin
Next:Microsoft.Office.Interop.Word document dynamically generates tables
Posted on 2/1/2016 10:27:11 AM |
The whole code of the plugin is put up
 Landlord| Posted on 3/2/2016 10:43:08 AM |
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com