经常会遇到转换文件为bas64格式,可以使用如下链接
https://aqwu.net/tools/png.html
源代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<!DOCTYPE html> <html lang="cn"> <head> <title>杰力皓博</title> <meta charset="utf-8" /> <meta name="referrer" content="same-origin" /> <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <meta name="keywords" content="杰力皓博"> <style> .content{ width: 400px; margin: auto; } </style> </head> <body> <script> window.onload=function() { prv_staus.value = ""; prvfile.onchange=function(e) { var files = this.files; console.log(files); var selectedfile = files[0]; var reader = new FileReader(); reader.readAsDataURL(selectedfile); reader.onload = function(event){ prv_staus.value = event.target.result; } } } </script> <div class="content"> <h1>选择文件转成base64</h1> <br/> <input type="file" id="prvfile"/> <br/> <textarea id="prv_staus" name="" rows="25" cols="50" placeholder="选择文件文件"></textarea> </div> </body> </html> |