File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments