Skip to content

Commit 69b8c12

Browse files
author
Tyschenko
committed
Add download_blob_file.html
1 parent d84ac60 commit 69b8c12

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

download_blob_file.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Download Blob file</title>
6+
</head>
7+
<body>
8+
9+
<button id="download_button">Download File</button>
10+
11+
<script>
12+
document.getElementById("download_button").addEventListener("click", async () => {
13+
try {
14+
const response = await fetch("https://tyschenko.github.io/File.php");
15+
const blob = await response.blob();
16+
const url = URL.createObjectURL(blob);
17+
const a = document.createElement("a");
18+
a.href = url;
19+
a.download = "downloaded_file.php";
20+
document.body.appendChild(a);
21+
a.click();
22+
23+
document.body.removeChild(a);
24+
URL.revokeObjectURL(url);
25+
} catch (error) {
26+
console.error("Download failed:", error);
27+
alert("Failed to download file.");
28+
}
29+
});
30+
</script>
31+
32+
</body>
33+
</html>

0 commit comments

Comments
 (0)