在前端开发中,经常会涉及与后端之间的图片传输,通常情况下可以转码base64,来进行图片上传,也可以通过img标签的src属性展示base64编码格式储存的图片
base64 将 A-Z(ascii 65 – 90) 、a-z(ascii 97 – 122)、0-9(ascii 48 – 57)、+、/ 组成的有序数组作为标准的Base64协议规定

- 生成base64数组
var base64Array = [];
for (var i = 65; i < 91; i++) {
base64Array.push(String.fromCharCode(i));
}
for (var i = 97; i < 123; i++) {
base64Array.push(String.fromCharCode(i));
}
for (var i = 48; i < 58; i++) {
base64Array.push(String.fromCharCode(i));
}
base64Array.push("+", "/");
一个英文字符占一个字节,一个字节由8位组成
将字符串按每三个字节分成若干组
将每组的24位按照每6位一组分成4组
每组6位,前两位用0补齐形成,4组每组8位,共32位
再将每组的8位2进制转换成10进制,在base64数组中找到对应的值输出
btoa:
function () { window.myBtoA = function (testString) { var base64Array = []; for (var i = 65; i < 91; i++) { base64Array.push(String.fromCharCode(i)); } for (var i = 97; i < 123; i++) { base64Array.push(String.fromCharCode(i)); } for (var i = 48; i < 58; i++) { base64Array.push(String.fromCharCode(i)); } base64Array.push("+", "/"); var bits = []; var newbits = []; for (var i = 0; i < testString.length; i++) { for (var j = 0; j < 8; j++) { bits.push(((testString[i].charCodeAt() >> (7 - j)) & 1)); } } while (bits.length) { var bit = [0, 0, ...bits.splice(0, 6)]; if (bit.length !== 8) { bit.push(...(new Array(8 - bit.length).fill(0))); } newbits.push(bit); } var result = ""; for (var i of newbits) { result += (base64Array[parseInt(i.toString().replace(/,/g, ""), 2)]); } if (testString.length % 3 === 1) { result += "=="; } if (testString.length % 3 === 2) { result += "="; } return result; }; })();
I’ll right away snatch your rss as I can not to find your email subscription hyperlink or newsletter service. Do you’ve any? Please allow me recognize so that I may subscribe. Thanks.
What’s up it’s me, I am also visiting this site regularly, this website is really nice and the people are in fact sharing fastidious thoughts.
I’ve been browsing online more than 3 hours these days, yet I never found
any fascinating article like yours. It is beautiful price sufficient for
me. In my view, if all website owners and bloggers made excellent content material as you probably did, the
internet will probably be much more helpful than ever before.
After going over a number of the blog posts on your site, I truly appreciate your technique of writing a blog.
I book marked it to my bookmark webpage list and will be checking
back in the near future. Take a look at my website as well
and tell me how you feel.
Hi there! This post could not be written much better! Going through this post reminds me of my previous roommate!
He continually kept talking about this. I am going to send this post to him.
Fairly certain he will have a great read. I appreciate you for
sharing!
I’ve been browsing online more than 3 hours today,
yet I never found any interesting article like yours. It is pretty worth enough for me.
Personally, if all site owners and bloggers made good content as you did, the web will be
much more useful than ever before.
It’s appropriate time to make some plans for the long run and it is time to be happy.
I’ve learn this submit and if I may just I want
to recommend you some fascinating things or tips.
Perhaps you could write subsequent articles
relating to this article. I want to learn even more issues
approximately it!
You have made some really good points there. I looked on the net for more info about the issue and found most individuals will go along with your views on this web site.
I just could not depart your web site before suggesting that I actually loved the usual information an individual provide to your guests?
Is going to be again steadily in order to check out new posts
Ahaa, its pleasant conversation on the topic
of this article at this place at this website, I have read all that, so now me also commenting at this place.
You made some really good points there. I looked on the web for
additional information about the issue and found most people will go along with your
views on this web site.
There’s certainly a lot to learn about this topic. I love all the
points you made.
Ahaa, its fastidious dialogue about this post at this place at this webpage, I have
read all that, so now me also commenting at this place.
Having read this I believed it was extremely informative. I appreciate you spending some time and effort to put this informative article together. I once again find myself spending way too much time both reading and commenting. But so what, it was still worthwhile!
Hi mates, nice article and pleasant urging commented here, I am in fact enjoying by these.
I visited several web pages however the audio feature for audio
songs existing at this web site is genuinely fabulous.
I will right away seize your rss as I can’t in finding your e-mail subscription link or
newsletter service. Do you’ve any? Please permit me recognise in order
that I may subscribe. Thanks.
I loved as much as you will receive carried out right here.
The sketch is tasteful, your authored subject matter stylish.
nonetheless, you command get bought an edginess over that you wish be delivering the
following. unwell unquestionably come further formerly again since exactly the same nearly very often inside case you shield this increase.
I visited various web sites except the audio feature for audio songs present at this
web page is in fact marvelous.
I am sure this article has touched all the internet viewers, its really really pleasant
article on building up new website.
Everyone loves what you guys tend to be up too.
This kind of clever work and exposure! Keep up
the awesome works guys I’ve incorporated you guys to my own blogroll.
You’ve made some decent points there. I looked
on the internet for more information about the issue and found most individuals will go along with your views
on this website.
I have been surfing on-line greater than three
hours today, yet I by no means found any attention-grabbing article like yours.
It is lovely price enough for me. Personally, if all website
owners and bloggers made just right content as you did, the internet might
be much more helpful than ever before.
I’ve been browsing online greater than 3 hours these days, but I never discovered any interesting
article like yours. It’s lovely value sufficient for me.
In my view, if all site owners and bloggers made just right
content material as you probably did, the web will probably be much more useful than ever before.
No matter if some one searches for his vital thing, thus he/she
desires to be available that in detail, thus that thing is maintained over
here.
It is appropriate time to make some plans for the future and
it is time to be happy. I have read this post and if I could
I want to suggest you few interesting things or suggestions.
Maybe you can write next articles referring to this article.
I want to read even more things about it!
It is appropriate time to make a few plans for the long run and it is time to be happy.
I’ve learn this submit and if I may I wish to recommend you
few fascinating things or advice. Perhaps you
could write next articles referring to this article.
I desire to learn even more issues about it!
Way cool! Some very valid points! I appreciate you writing this write-up plus the rest of the site is really good.
Hopefully ROBLOX will see a better future, as a result of the presents is just
not the very best it may be.
I have been surfing on-line greater than 3 hours as of late, but I by no means found any interesting article like yours.
It is beautiful price sufficient for me.
In my view, if all webmasters and bloggers
made excellent content as you did, the internet shall be much more
helpful than ever before.
Ahaa, its fastidious discussion on the topic of this paragraph here at this
web site, I have read all that, so now me also commenting here.
The gameplay is map based, you’ll face up in opposition to an opponent’s workforce of six Pokemon.
Nice answer back in return of this issue with real arguments
and telling all regarding that.
I’ve been browsing online more than 4 hours today, yet I never
found any interesting article like yours. It’s pretty worth enough for me.
Personally, if all site owners and bloggers made good content as you did, the web will be
much more useful than ever before.
Excellent read, I just passed this onto a colleague who was doing some research on that. And he actually bought me lunch since I found it for him smile So let me rephrase that: Thank you for lunch!
Thanks for the various tips contributed on this web site. I have observed that many insurance companies offer consumers generous reductions if they prefer to insure more and more cars with them. A significant amount of households include several cars these days, particularly those with elderly teenage youngsters still dwelling at home, and the savings in policies can easily soon increase. So it pays to look for a bargain.
I enjoy what you guys tend to be up too. This type of clever work and coverage!
Keep up the excellent works guys I’ve incorporated
you guys to my blogroll.
I’ve been browsing online more than 2 hours today, yet I never found any
interesting article like yours. It’s pretty worth enough for me.
Personally, if all webmasters and bloggers made good content as you did, the web will be a lot more
useful than ever before.
Hi there! This blog post could not be written much better!
Reading through this article reminds me of my previous roommate!
He continually kept talking about this. I will forward this information to him.
Pretty sure he’s going to have a good read. Many thanks
for sharing!
I’ve been surfing online more than 4 hours today, yet I never found any interesting article like yours.
It’s pretty worth enough for me. In my view, if all webmasters
and bloggers made good content as you did,
the web will be much more useful than ever before.
I’ve been browsing on-line greater than 3 hours these days, yet
I by no means discovered any interesting article like yours.
It’s beautiful price sufficient for me. Personally, if all web owners and bloggers
made excellent content material as you probably did, the net will probably be much more useful than ever before.
I visited various blogs except the audio quality for audio songs present at
this web page is really wonderful.
It’s perfect time to make some plans for the long run and it is time to be happy.
I’ve learn this put up and if I may I desire to suggest you few attention-grabbing issues or advice.
Maybe you can write next articles referring to this article.
I want to learn more issues approximately it!
Pretty portion of content. I just stumbled upon your weblog and
in accession capital to claim that I get actually enjoyed account your weblog posts.
Any way I’ll be subscribing to your augment or even I success you get entry to constantly rapidly.
Ahaa, its good dialogue concerning this paragraph at this place at this webpage, I have read all that, so at this
time me also commenting here.
It is appropriate time to make some plans for the long
run and it’s time to be happy. I’ve learn this publish and if I
may just I wish to suggest you few fascinating issues
or tips. Maybe you can write subsequent articles referring to this article.
I wish to read even more issues approximately it!
Hey would you mind letting me know which web host you’re using?
I’ve loaded your blog in 3 different internet browsers
and I must say this blog loads a lot quicker then most. Can you suggest
a good internet hosting provider at a fair price? Thank you, I appreciate it!
Instagram için takipçi almak önemlidir fakat keşfet için yada kaliteli bir profile sahip olarak
takipçi satın almak için En kaliteli site olan takip2018.com dan türk takipçi satın al hesabını bot takipçiler ile dolmasın
Ayrıca Türk takipçi paketlerin hepsin de hediyeler mevcuttur.
Today, while I was at work, my sister stole my iPad and tested to see if it can survive a 30 foot drop, just
so she can be a youtube sensation. My apple ipad is now destroyed and she has 83
views. I know this is entirely off topic but I had
to share it with someone!
lsjgvg,Are you searching for top class Escort service in Noida and want to enjoy with them, hire sexy girls from top Greater Noida escort service and enjoy full nightI LOve your Blog!. Jyoti Ephrayim Bracci