-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfile2base64.html
More file actions
38 lines (31 loc) · 1.09 KB
/
file2base64.html
File metadata and controls
38 lines (31 loc) · 1.09 KB
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
<html>
<body>
<center>
<p>Select a File to Load:</p>
<input id="inputFileToLoad" type="file" onchange="loadImageFileAsURL();">
<p>File Contents as DataURL:</p>
<textarea onfocus="this.select()" onmouseover="this.focus()" onclick="this.focus();this.select()" id="textAreaFileContents" style="width:640;height:240"></textarea>
<script type="text/javascript">
function loadImageFileAsURL()
{
var filesSelected = document.getElementById("inputFileToLoad").files;
if (filesSelected.length > 0)
{
var fileToLoad = filesSelected[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var textAreaFileContents = document.getElementById
(
"textAreaFileContents"
);
textAreaFileContents.innerHTML = fileLoadedEvent.target.result;
};
fileReader.readAsDataURL(fileToLoad);
}
}
</script>
<br><a href="https://thiscouldbebetter.wordpress.com/2013/07/03/converting-a-file-to-a-base64-dataurl-in-javascript/">kaynak</a><br>
</body>
</center>
</html>