diff --git a/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx b/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx index f737b1bc..7dcea4f7 100644 --- a/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx @@ -66,6 +66,7 @@ class ViewDocumentsClass extends BasePage { this.hasPrevious = this.hasPrevious.bind(this); this.hasNext = this.hasNext.bind(this); + this.downloadFile = this.downloadFile.bind(this); this.refuseDocument = this.refuseDocument.bind(this); } @@ -119,9 +120,7 @@ class ViewDocumentsClass extends BasePage { )} {this.state.document?.document_status === "VALIDATED" && ( - - - + )} @@ -199,6 +198,30 @@ class ViewDocumentsClass extends BasePage { } } + private downloadFile() { + const fileName = this.state.selectedFile?.file_path?.split("/").pop(); + fetch(this.state.selectedFile?.file_path as string) + .then((resp) => resp.blob()) + .then((blob) => { + const url = window.URL.createObjectURL(blob); + const a = document.createElement("a"); + a.style.display = "none"; + a.href = url; + // the filename you want + a.download = fileName as string; + document.body.appendChild(a); + a.click(); + window.URL.revokeObjectURL(url); + }) + .catch((e) => { + const a = document.createElement("a"); + a.href = this.state.selectedFile?.file_path as string; + a.target = "_blank"; + a.click(); + console.error(e); + }); + } + private getRandomPercentageForOcr() { // find diff let difference = 100 - 90;