From 978f9ad9596c4511c02ca10ff7581cda4402c6cd Mon Sep 17 00:00:00 2001 From: sergesoroka Date: Wed, 4 Sep 2024 07:26:11 +0200 Subject: [PATCH] Download the file button --- components/h5web/h5web.jsx | 27 +++++++++++++++++++++++++-- src/App.css | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/components/h5web/h5web.jsx b/components/h5web/h5web.jsx index eeb0dad..b2fbc70 100755 --- a/components/h5web/h5web.jsx +++ b/components/h5web/h5web.jsx @@ -21,11 +21,34 @@ export default function H5web({ domain }) { const initialPath = initialPathParams ? initialPathParams : hash ? hash : '/' - + const downloadFile = () => { + fetch(`${import.meta.env.VITE_BaseURL}download?what=h5&domain=${domain}`) + .then(resp => resp.blob()) + .then(blob => { + const url = window.URL.createObjectURL(blob); + const a = document.createElement("a"); + a.style.display = "none"; + a.href = url; + a.download = `${domain}`; + document.body.appendChild(a); + a.click(); + window.URL.revokeObjectURL(url); + + }) + .catch(() => alert("oh no!")); +} return (
-
+
+ +
+