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 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 >
You can’t perform that action at this time.
0 commit comments