Skip to content

Commit

Permalink
fix: google drive file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Aug 7, 2023
1 parent ad6f68f commit 52baa21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface Props {
interface DragAndDropProps {
disabled: boolean;
handleNext: () => void;
setFile: React.Dispatch<React.SetStateAction<File | string | null>>;
setFile: React.Dispatch<React.SetStateAction<File | null>>;
}

export default function AddDatasetFragment(props: DragAndDropProps) {
Expand All @@ -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();
});
}
Expand Down Expand Up @@ -116,6 +118,7 @@ export default function AddDatasetFragment(props: DragAndDropProps) {
</ul>
</li>
));

return (
<>
<DropZone
Expand Down
4 changes: 1 addition & 3 deletions src/app/fragments/datasets-fragment/upload-steps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import AddDatasetFragment from "app/fragments/datasets-fragment/upload-steps/add

export default function DatasetUploadSteps() {
const [activeStep, setActiveStep] = React.useState<number>(0);
const [selectedFile, setSelectedFile] = React.useState<File | string | null>(
null
);
const [selectedFile, setSelectedFile] = React.useState<File | null>(null);
const [uploading, setUploading] = React.useState(false);
const [uploadSuccess, setUploadSuccess] = React.useState(false);
const [processingError, setProcessingError] = React.useState(false);
Expand Down

0 comments on commit 52baa21

Please sign in to comment.