From 88ef46917887557d9624d52198b48055f317ea68 Mon Sep 17 00:00:00 2001 From: khavinshankar Date: Tue, 16 Jan 2024 17:09:55 +0530 Subject: [PATCH 1/4] feat: whitelist file types in file upload --- src/Components/Patient/FileUpload.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Components/Patient/FileUpload.tsx b/src/Components/Patient/FileUpload.tsx index e1ea368af72..b4b7acef0e3 100644 --- a/src/Components/Patient/FileUpload.tsx +++ b/src/Components/Patient/FileUpload.tsx @@ -1021,6 +1021,7 @@ export const FileUpload = (props: FileUploadProps) => { name: filename, associating_id: getAssociatedId(), file_category: category, + mime_type: f?.type, }; dispatch(createUpload(requestData)) .then(uploadfile) @@ -1105,6 +1106,7 @@ export const FileUpload = (props: FileUploadProps) => { name: filename, associating_id: getAssociatedId(), file_category: category, + mime_type: "audio/mpeg", }; dispatch(createUpload(requestData)) .then(uploadAudiofile) @@ -1532,6 +1534,7 @@ export const FileUpload = (props: FileUploadProps) => { title="changeFile" onChange={onFileChange} type="file" + accept="image/jpeg,image/png,application/pdf" hidden /> From bc8e1317a835c4802b9a7b1bc39a744470402b84 Mon Sep 17 00:00:00 2001 From: khavinshankar Date: Tue, 16 Jan 2024 17:56:26 +0530 Subject: [PATCH 2/4] fix: updated the whitelisted filetypes --- src/Components/Patient/FileUpload.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Patient/FileUpload.tsx b/src/Components/Patient/FileUpload.tsx index b4b7acef0e3..1da3af40ef7 100644 --- a/src/Components/Patient/FileUpload.tsx +++ b/src/Components/Patient/FileUpload.tsx @@ -1534,7 +1534,7 @@ export const FileUpload = (props: FileUploadProps) => { title="changeFile" onChange={onFileChange} type="file" - accept="image/jpeg,image/png,application/pdf" + accept="image/*,video/*,audio/*,text/plain,text/csv,application/rtf,application/msword,application/vnd.oasis.opendocument.text,application/pdf,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.oasis.opendocument.spreadsheet,application/pdf" hidden /> From d6e08f31cc16c6904d56c4b97ac1e25e976aa79e Mon Sep 17 00:00:00 2001 From: khavinshankar Date: Wed, 17 Jan 2024 17:20:38 +0530 Subject: [PATCH 3/4] fix audio recording upload and image capture upload --- src/Components/Patient/FileUpload.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Components/Patient/FileUpload.tsx b/src/Components/Patient/FileUpload.tsx index 1da3af40ef7..bfdb44119b8 100644 --- a/src/Components/Patient/FileUpload.tsx +++ b/src/Components/Patient/FileUpload.tsx @@ -165,7 +165,6 @@ export const FileUpload = (props: FileUploadProps) => { const [fileUrl, setFileUrl] = useState(""); const [audioName, setAudioName] = useState(""); const [audioFileError, setAudioFileError] = useState(""); - const [contentType, setcontentType] = useState(""); const [downloadURL, setDownloadURL] = useState(); const FACING_MODE_USER = "user"; const FACING_MODE_ENVIRONMENT = { exact: "environment" }; @@ -248,7 +247,7 @@ export const FileUpload = (props: FileUploadProps) => { fetch(webRef.current.getScreenshot()) .then((res) => res.blob()) .then((blob) => { - const myFile = new File([blob], "image.png", { + const myFile = new File([blob], `image.${blob.type.split("/").pop()}`, { type: blob.type, }); setFile(myFile); @@ -918,7 +917,6 @@ export const FileUpload = (props: FileUploadProps) => { ); const ext: string = fileName.split(".")[1]; - setcontentType(header_content_type[ext]); if (ExtImage.includes(ext)) { const options = { @@ -942,7 +940,7 @@ export const FileUpload = (props: FileUploadProps) => { const config = { headers: { - "Content-type": contentType, + "Content-type": file?.type, "Content-disposition": "inline", }, onUploadProgress: (progressEvent: any) => { @@ -1052,8 +1050,12 @@ export const FileUpload = (props: FileUploadProps) => { const internal_name = response.data.internal_name; const f = audioBlob; if (f === undefined) return; - const newFile = new File([f], `${internal_name}`, { type: "audio/mpeg" }); + const newFile = new File([f], `${internal_name}`, { type: f.type }); const config = { + headers: { + "Content-type": newFile?.type, + "Content-disposition": "inline", + }, onUploadProgress: (progressEvent: any) => { const percentCompleted = Math.round( (progressEvent.loaded * 100) / progressEvent.total @@ -1065,7 +1067,7 @@ export const FileUpload = (props: FileUploadProps) => { axios .put(url, newFile, config) .then(() => { - setAudioUploadStarted(false); + setAudioUploadStarted(true); // setUploadSuccess(true); setAudioName(""); setReload(!reload); @@ -1106,7 +1108,7 @@ export const FileUpload = (props: FileUploadProps) => { name: filename, associating_id: getAssociatedId(), file_category: category, - mime_type: "audio/mpeg", + mime_type: audioBlob?.type, }; dispatch(createUpload(requestData)) .then(uploadAudiofile) From ec4df21ad3c6a5ca8b5ffd7061f6cffed9014f83 Mon Sep 17 00:00:00 2001 From: khavinshankar Date: Wed, 17 Jan 2024 17:33:35 +0530 Subject: [PATCH 4/4] fix file upload progress state --- src/Components/Patient/FileUpload.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Patient/FileUpload.tsx b/src/Components/Patient/FileUpload.tsx index 600964fa66f..02de804f162 100644 --- a/src/Components/Patient/FileUpload.tsx +++ b/src/Components/Patient/FileUpload.tsx @@ -1068,7 +1068,7 @@ export const FileUpload = (props: FileUploadProps) => { axios .put(url, newFile, config) .then(() => { - setAudioUploadStarted(true); + setAudioUploadStarted(false); // setUploadSuccess(true); setAudioName(""); setReload(!reload);