diff --git a/src/Components/Patient/FileUpload.tsx b/src/Components/Patient/FileUpload.tsx index 9943761fc12..5658bfa8ed7 100644 --- a/src/Components/Patient/FileUpload.tsx +++ b/src/Components/Patient/FileUpload.tsx @@ -36,6 +36,7 @@ import { VoiceRecorder } from "../../Utils/VoiceRecorder"; import { makeStyles, Theme, createStyles } from "@material-ui/core/styles"; import Modal from "@material-ui/core/Modal"; import { Close } from "@material-ui/icons"; +import { BrowserClient } from "@sentry/browser"; const Loading = loadable(() => import("../Common/Loading")); const PageTitle = loadable(() => import("../Common/PageTitle")); @@ -142,6 +143,7 @@ export const FileUpload = (props: FileUploadProps) => { const classes = useStyles(); const [modalStyle] = React.useState(getModalStyle); const [open, setOpen] = React.useState(false); + const [downloadURL, setDownloadURL] = useState(); const UPLOAD_HEADING: { [index: string]: string } = { PATIENT: "Upload Patient Files", @@ -157,6 +159,7 @@ export const FileUpload = (props: FileUploadProps) => { }; const handleClose = () => { + setDownloadURL(""); setOpen(false); }; @@ -222,6 +225,7 @@ export const FileUpload = (props: FileUploadProps) => { var data = { file_type: type, associating_id: getAssociatedId() }; var responseData = await dispatch(retrieveUpload(data, id)); // window.open(responseData.data.read_signed_url, "_blank"); + downloadFileUrl(responseData.data.read_signed_url); setFileUrl(responseData.data.read_signed_url); }; @@ -412,6 +416,15 @@ export const FileUpload = (props: FileUploadProps) => { }); }; + // For creating the Download File URL + const downloadFileUrl = (url: string) => { + fetch(url) + .then((res) => res.blob()) + .then((blob) => { + setDownloadURL(URL.createObjectURL(blob)); + }); + }; + return (
{ > {fileUrl && fileUrl.length > 0 ? ( <> -
- +
+ {downloadURL && downloadURL.length > 0 && ( + + )} + +
+ +