How do I convert base64 to an html file?
Use it with iframe
. Simply make sure you use the correct data (data:text/html;charset=utf-8;base64
) and that you have a valid converted HTML
iframe {
border:none;
width:100%;
height:1000px;
}
body {
margin:0;
}
<iframe src="data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+DQo8aHRtbD4NCjxoZWFkPjxtZXRhIG5hbWU9ImNoYXJzZXQiIGNvbnRlbnQ9InV0Zi04Ij4NCiAgPHRpdGxlPjwvdGl0bGU+DQogIDwvaGVhZD4NCiAgPGJvZHk+DQogICAgPGRpdiBhbGlnbj0iY2VudGVyIj4NCiAgICAgIDxhIGhyZWY9Imh0dHA6Ly9ubGljLnNwZWVkb21haWxodWIuaW4vY2FtcGFpZ25zL2RqMzk0eWtocDM5MmMvdHJhY2stdXJsL2F3MzUxYXhidHY3ZjYvOWMxODcyOTQ0NWRjY2EzNmU0NWVmYzBkYWE0Yzk0YmUxOGIxOThhYSI+DQogICAgICA8aW1nIGFsdD0iIiBzcmM9Imh0dHA6Ly9oYXNxLnNwZWVkb21haWxodWIuaW4vc2s1NTExOWdiODkwMC9kajM5NHlraHAzOTJjL3ZxMDE1eHo3YmExYzJfMS5wbmciPjwvYT4NCiAgICA8L2Rpdj4NCiAgICANCiAgICA8ZGl2IHN0eWxlPSJ0ZXh0LWFsaWduOmNlbnRlcjsiPllvdSBjYW4gc2ltcGx5IFdJUEUgT3V0IHlvdXIgZW1haWwgZnJvbSBNYWlsaW5nIExpc3TDgiA8YSBocmVmPSJodHRwOi8vbmxpYy5zcGVlZG9tYWlsaHViLmluL2xpc3RzL2xjNzMxN2hhaGczZDgvdW5zdWJzY3JpYmUvYXczNTFheGJ0djdmNi9kajM5NHlraHAzOTJjLzMiIHRhcmdldD0iX2JsYW5rIj4gY2xpY2sgaGVyZSA8L2E+DQogICAgPC9kaXY+DQogICAgDQogICAgPGltZyB3aWR0aD0iMSIgc3JjPSJodHRwOi8vbmxpYy5zcGVlZG9tYWlsaHViLmluL2NhbXBhaWducy9kajM5NHlraHAzOTJjL3RyYWNrLW9wZW5pbmcvYXczNTFheGJ0djdmNiIgYWx0PSIiLz4NCiAgPC9ib2R5Pg0KICANCiAgPC9odG1sPg=="></iframe>
Vruksha Nikam
Updated on December 12, 2022Comments
-
Vruksha Nikam over 1 year
I am getting a mail body encoded in base64:
PCFET0NUWVBFIGh0bWw-PGhlYWQ-PG1ldGEgbmFtZT0iY2hhcnNldCIgY29udGVudD0idXRmLTgiPjx0aXRsZT48L3RpdGxlPjwvaGVhZD48Ym9keT4NCg0KICAgICAgICAgICAgPGRpdiBhbGlnbj0iY2VudGVyIj4KICAgICAgPGEgaHJlZj0iaHR0cDovL25saWMuc3BlZWRvbWFpbGh1Yi5pbi9jYW1wYWlnbnMvZGozOTR5a2hwMzkyYy90cmFjay11cmwvYXczNTFheGJ0djdmNi85YzE4NzI5NDQ1ZGNjYTM2ZTQ1ZWZjMGRhYTRjOTRiZTE4YjE5OGFhIj48aW1nIGFsdD0iIiBzcmM9Imh0dHA6Ly9oYXNxLnNwZWVkb21haWxodWIuaW4vc2s1NTExOWdiODkwMC9kajM5NHlraHAzOTJjL3ZxMDE1eHo3YmExYzJfMS5wbmciPjwvYT4KICAgIDwvZGl2PjxkaXYgc3R5bGU9InRleHQtYWxpZ246Y2VudGVyOyI-WW91IGNhbiBzaW1wbHkgV0lQRSBPdXQgeW91ciBlbWFpbCBmcm9tIE1haWxpbmcgTGlzdMKgPGEgaHJlZj0iaHR0cDovL25saWMuc3BlZWRvbWFpbGh1Yi5pbi9saXN0cy9sYzczMTdoYWhnM2Q4L3Vuc3Vic2NyaWJlL2F3MzUxYXhidHY3ZjYvZGozOTR5a2hwMzkyYy8zIiB0YXJnZXQ9Il9ibGFuayI-IGNsaWNrIGhlcmUgPC9hPjwvZGl2Pgo8aW1nIHdpZHRoPSIxIiBzcmM9Imh0dHA6Ly9ubGljLnNwZWVkb21haWxodWIuaW4vY2FtcGFpZ25zL2RqMzk0eWtocDM5MmMvdHJhY2stb3BlbmluZy9hdzM1MWF4YnR2N2Y2IiBhbHQ9IiIvPjwvYm9keT48L2h0bWw-DQoNCg==
I have an html page:
<a href="data:text/css;base64,PCFET0NUWVBFIGh0bWw-PGhlYWQ-PG1ldGEgbmFtZT0iY2hhcnNldCIgY29udGVudD0idXRmLTgiPjx0aXRsZT48L3RpdGxlPjwvaGVhZD48Ym9keT4NCg0KICAgICAgICAgICAgPGRpdiBhbGlnbj0iY2VudGVyIj4KICAgICAgPGEgaHJlZj0iaHR0cDovL25saWMuc3BlZWRvbWFpbGh1Yi5pbi9jYW1wYWlnbnMvZGozOTR5a2hwMzkyYy90cmFjay11cmwvYXczNTFheGJ0djdmNi85YzE4NzI5NDQ1ZGNjYTM2ZTQ1ZWZjMGRhYTRjOTRiZTE4YjE5OGFhIj48aW1nIGFsdD0iIiBzcmM9Imh0dHA6Ly9oYXNxLnNwZWVkb21haWxodWIuaW4vc2s1NTExOWdiODkwMC9kajM5NHlraHAzOTJjL3ZxMDE1eHo3YmExYzJfMS5wbmciPjwvYT4KICAgIDwvZGl2PjxkaXYgc3R5bGU9InRleHQtYWxpZ246Y2VudGVyOyI-WW91IGNhbiBzaW1wbHkgV0lQRSBPdXQgeW91ciBlbWFpbCBmcm9tIE1haWxpbmcgTGlzdMKgPGEgaHJlZj0iaHR0cDovL25saWMuc3BlZWRvbWFpbGh1Yi5pbi9saXN0cy9sYzczMTdoYWhnM2Q4L3Vuc3Vic2NyaWJlL2F3MzUxYXhidHY3ZjYvZGozOTR5a2hwMzkyYy8zIiB0YXJnZXQ9Il9ibGFuayI-IGNsaWNrIGhlcmUgPC9hPjwvZGl2Pgo8aW1nIHdpZHRoPSIxIiBzcmM9Imh0dHA6Ly9ubGljLnNwZWVkb21haWxodWIuaW4vY2FtcGFpZ25zL2RqMzk0eWtocDM5MmMvdHJhY2stb3BlbmluZy9hdzM1MWF4YnR2N2Y2IiBhbHQ9IiIvPjwvYm9keT48L2h0bWw-DQoNCg==" />See html</a>
which on clicking See html opens a file with html written in the form of text:
<!DOCTYPE html> <head><meta name="charset" content="utf-8"> <title></title> </head> <body> <div align="center"> <a href="http://nlic.speedomailhub.in/campaigns/dj394ykhp392c/track-url/aw351axbtv7f6/9c18729445dcca36e45efc0daa4c94be18b198aa"> <img alt="" src="http://hasq.speedomailhub.in/sk55119gb8900/dj394ykhp392c/vq015xz7ba1c2_1.png"></a> </div> <div style="text-align:center;">You can simply WIPE Out your email from Mailing List <a href="http://nlic.speedomailhub.in/lists/lc7317hahg3d8/unsubscribe/aw351axbtv7f6/dj394ykhp392c/3" target="_blank"> click here </a> </div> <img width="1" src="http://nlic.speedomailhub.in/campaigns/dj394ykhp392c/track-opening/aw351axbtv7f6" alt=""/> </body> </html>
How do I show this as an actual html file, just like it shows on run code instead of just plain html text.
Is there any way I can directly convert the base64 to an actual html page. IS it possible with python?
-
collapsar almost 5 years(Unrelated to your actual question) The data url in the
a
element'shref
attribute starts withdata:text/css
which denotes a css ruleset and not html. Better usedata:text/html
.
-
-
collapsar almost 5 yearsWhy do you think this is some image data? While the decoded text stream seems to be partially corrupted the intelligible fragments clearly show that it originates from html (though the data url is mislabeled wrt the MIME type (text/css instead of text/html)
-
Vadim Hulevich almost 5 years@collapsar Because in example i see image, and base64 usually used for image, it's a weird use base64 for source html code
-
collapsar almost 5 yearsIn the example you see a html page that happens to contain graphics. You are mistaken in believing that base64 is 'usually used for image' - it is used for any kind of binary data that is processed by systems that assume ascii textual data. Historically that has been email (I'd suspect that pdf attachments are the most common use case). Using base64 for html source code (or any other content) is not weird btw; eg. you might want to avoid issues character set issues with the software handling the data.