From 312c8754bceb5ab577032f66be259fa92fbd5a0d Mon Sep 17 00:00:00 2001 From: Morten Olsen Date: Wed, 19 Aug 2020 17:26:34 +0200 Subject: [PATCH] download --- src/components/File.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/File.tsx b/src/components/File.tsx index 35027fb..e0a0d8e 100644 --- a/src/components/File.tsx +++ b/src/components/File.tsx @@ -9,6 +9,15 @@ interface Props { file: File; } +const downloadLink = (name: string, url: string) => { + const downloadLink = document.createElement('a'); + downloadLink.href = url; + downloadLink.download = name; + document.body.appendChild(downloadLink); + downloadLink.click(); + document.body.removeChild(downloadLink); +}; + const Button = styled.button` background: none; border: none; @@ -37,9 +46,7 @@ const FileView: React.FC = ({ right={!!file.link && ( <> - - - +