Skip to content

Commit 5ba981a

Browse files
author
Tyschenko
committed
Add download_base64_file.html
1 parent 69b8c12 commit 5ba981a

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

download_base64_file.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Download Base64 file</title>
6+
</head>
7+
<body>
8+
9+
<button id="download_button">Download file</button>
10+
<p id="result"></p>
11+
12+
<script>
13+
document.getElementById("download_button").addEventListener("click", async () => {
14+
const resultElement = document.getElementById("result");
15+
resultElement.textContent = "Loading...";
16+
17+
const response = await fetch("https://tyschenko.github.io/File.php");
18+
const blob = await response.blob();
19+
20+
const reader = new FileReader();
21+
reader.onloadend = () => {
22+
const base64DataUrl = reader.result;
23+
24+
const link = document.createElement("a");
25+
link.href = base64DataUrl;
26+
link.textContent = "Click here to download (Base64)";
27+
link.download = "downloaded_file.php";
28+
29+
resultElement.innerHTML = "";
30+
resultElement.appendChild(link);
31+
};
32+
33+
reader.readAsDataURL(blob);
34+
});
35+
</script>
36+
37+
</body>
38+
</html>

0 commit comments

Comments
 (0)