Added logic for save to disk btn

This commit is contained in:
Max W. 2024-03-05 23:57:45 +01:00
parent b8b0242240
commit f944af2514
2 changed files with 16 additions and 6 deletions

View File

@ -52,7 +52,9 @@
<p class="text-xl font-bold text-center text-gray-800 mb-6">Download complete!</p> <p class="text-xl font-bold text-center text-gray-800 mb-6">Download complete!</p>
<p class="text-gray-600 text-center w-2/3 mb-3">File <strong>{{ fileName }}</strong> has been downloaded and saved to your drive.</p> <p class="text-gray-600 text-center w-2/3 mb-3">File <strong>{{ fileName }}</strong> has been downloaded and saved to your drive.</p>
<p class="text-gray-600 text-center w-2/3 mb-6">The download took {{ downloadDuration }} seconds.</p> <p class="text-gray-600 text-center w-2/3 mb-6">The download took {{ downloadDuration }} seconds.</p>
<button class="btn btn-primary w-full max-w-md flex justify-center items-center mb-4 hover:scale-105 transition-transform duration-100" > <button
(click)="saveDownloadedFile()"
class="btn btn-primary w-full max-w-md flex justify-center items-center mb-4 hover:scale-105 transition-transform duration-100" >
Save to disk (again) Save to disk (again)
</button> </button>
<button class="btn btn-primary w-full max-w-md flex justify-center items-center mb-4 hover:scale-105 transition-transform duration-100" routerLink="/home"> <button class="btn btn-primary w-full max-w-md flex justify-center items-center mb-4 hover:scale-105 transition-transform duration-100" routerLink="/home">

View File

@ -175,13 +175,14 @@ export class DownloadComponent {
const a = document.createElement('a'); const a = document.createElement('a');
a.style.display = 'none'; a.style.display = 'none';
a.href = url; a.href = url;
a.download = filename; // You can specify a filename here a.download = filename;
a.id = 'fileDownloadBlob';
document.body.appendChild(a); document.body.appendChild(a);
a.click(); this.saveDownloadedFile();
// Clean up by revoking the Blob URL and removing the temporary anchor // Clean up by revoking the Blob URL and removing the temporary anchor (currently disabled due to saveDownloadBtn)
window.URL.revokeObjectURL(url); // window.URL.revokeObjectURL(url);
document.body.removeChild(a); // document.body.removeChild(a);
}) })
.catch(error => { .catch(error => {
this.fileDownloadStarted = false; this.fileDownloadStarted = false;
@ -203,6 +204,13 @@ export class DownloadComponent {
this.downloadProgress = this.targetUploadProgress; this.downloadProgress = this.targetUploadProgress;
} }
} }
saveDownloadedFile() {
const a = document.getElementById('fileDownloadBlob');
if(a) {
a.click();
}
}
} }
interface DownloadInfo { interface DownloadInfo {
downloadable: boolean; downloadable: boolean;