From 52baa21cd12b3bdc63e775860d712794fe4e59ec Mon Sep 17 00:00:00 2001 From: Stefanos Hadjipetrou Date: Mon, 7 Aug 2023 18:06:04 +0300 Subject: [PATCH] fix: google drive file upload --- .../upload-steps/addDatasetFragment.tsx | 15 +++++++++------ .../datasets-fragment/upload-steps/index.tsx | 4 +--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/app/fragments/datasets-fragment/upload-steps/addDatasetFragment.tsx b/src/app/fragments/datasets-fragment/upload-steps/addDatasetFragment.tsx index 82c4020eb..b8250e1ff 100644 --- a/src/app/fragments/datasets-fragment/upload-steps/addDatasetFragment.tsx +++ b/src/app/fragments/datasets-fragment/upload-steps/addDatasetFragment.tsx @@ -26,7 +26,7 @@ interface Props { interface DragAndDropProps { disabled: boolean; handleNext: () => void; - setFile: React.Dispatch>; + setFile: React.Dispatch>; } export default function AddDatasetFragment(props: DragAndDropProps) { @@ -35,19 +35,21 @@ export default function AddDatasetFragment(props: DragAndDropProps) { React.useEffect(() => { if (authResponse?.access_token && fileData?.docs) { + const file = fileData?.docs[0]; axios({ - url: `https://www.googleapis.com/drive/v3/files/${fileData?.docs[0].id}?alt=media`, + url: `https://www.googleapis.com/drive/v3/files/${file.id}${ + file.type === "file" ? "?alt=media" : "/export?mimeType=text/csv" + }`, method: "GET", headers: { Authorization: `Bearer ${authResponse?.access_token}`, - "Content-Type": "application/vnd.google-apps.document", }, responseType: "blob", // important }).then((response) => { - console.log(response.data, "response.data"); + console.log("response", response); const b = response.data; - const file = new File([b], fileData?.docs[0].name, { type: b.type }); - props.setFile(file); + const gfile = new File([b], file.name, { type: "text/csv" }); + props.setFile(gfile); props.handleNext(); }); } @@ -116,6 +118,7 @@ export default function AddDatasetFragment(props: DragAndDropProps) { )); + return ( <> (0); - const [selectedFile, setSelectedFile] = React.useState( - null - ); + const [selectedFile, setSelectedFile] = React.useState(null); const [uploading, setUploading] = React.useState(false); const [uploadSuccess, setUploadSuccess] = React.useState(false); const [processingError, setProcessingError] = React.useState(false);