Skip to content

Commit 02ee9b2

Browse files
large file upload changes
1 parent 3144d6f commit 02ee9b2

File tree

1 file changed

+29
-38
lines changed

1 file changed

+29
-38
lines changed

frontend/src/components/DropZone.tsx

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import axios from 'axios';
12
import { Dropzone, Flex, Typography } from '@neo4j-ndl/react';
23
import React, { useState, useEffect, FunctionComponent } from 'react';
34
import Loader from '../utils/Loader';
45
import { v4 as uuidv4 } from 'uuid';
56
import { useCredentials } from '../context/UserCredentials';
67
import { useFileContext } from '../context/UsersFiles';
78
import CustomAlert from './Alert';
8-
import { CustomFile, CustomFileBase, UserCredentials, alertStateType } from '../types';
9+
import { CustomFile, CustomFileBase, UploadResponse, alertStateType } from '../types';
910
import { buttonCaptions, chunkSize } from '../utils/Constants';
11+
import { url } from '../utils/Utils';
1012
import { InformationCircleIconOutline } from '@neo4j-ndl/react/icons';
1113
import IconButtonWithToolTip from './IconButtonToolTip';
12-
import { uploadAPI } from '../utils/FileAPI';
1314

1415
const DropZone: FunctionComponent = () => {
1516
const { filesData, setFilesData, model } = useFileContext();
@@ -50,7 +51,6 @@ const DropZone: FunctionComponent = () => {
5051
type: `${file.name.substring(file.name.lastIndexOf('.') + 1, file.name.length).toUpperCase()}`,
5152
size: file.size,
5253
uploadprogess: file.size && file?.size < chunkSize ? 100 : 0,
53-
// total_pages: 0,
5454
id: uuidv4(),
5555
...defaultValues,
5656
});
@@ -121,11 +121,14 @@ const DropZone: FunctionComponent = () => {
121121
})
122122
);
123123
try {
124-
const apiResponse=await uploadAPI(chunk,userCredentials as UserCredentials,model,chunkNumber,totalChunks,file.name)
124+
const apiResponse = await axios.post<UploadResponse>(`${url()}/upload`, formData, {
125+
headers: {
126+
'Content-Type': 'multipart/form-data',
127+
},
128+
});
129+
125130
if (apiResponse?.data.status === 'Failed') {
126-
throw new Error(
127-
JSON.stringify({ message: apiResponse.data.message, fileName: apiResponse.data.file_name })
128-
);
131+
throw new Error(`message:${apiResponse.data.message},fileName:${apiResponse.data.file_name}`);
129132
} else {
130133
if (apiResponse.data.data) {
131134
setFilesData((prevfiles) =>
@@ -134,7 +137,6 @@ const DropZone: FunctionComponent = () => {
134137
return {
135138
...curfile,
136139
uploadprogess: chunkNumber * chunkProgressIncrement,
137-
// total_pages: apiResponse.data.data.total_pages,
138140
};
139141
}
140142
return curfile;
@@ -162,35 +164,24 @@ const DropZone: FunctionComponent = () => {
162164
uploadNextChunk();
163165
}
164166
} catch (error) {
165-
if (error instanceof Error) {
166-
setIsLoading(false);
167-
if (error.name === 'AxiosError') {
168-
setalertDetails({
169-
showAlert: true,
170-
alertType: 'error',
171-
alertMessage: error.message,
172-
});
173-
} else {
174-
const parsedError = JSON.parse(error.message);
175-
setalertDetails({
176-
showAlert: true,
177-
alertType: 'error',
178-
alertMessage: parsedError.message,
179-
});
180-
}
181-
setFilesData((prevfiles) =>
182-
prevfiles.map((curfile) => {
183-
if (curfile.name == file.name) {
184-
return {
185-
...curfile,
186-
status: 'Failed',
187-
type: `${file.name.substring(file.name.lastIndexOf('.') + 1, file.name.length).toUpperCase()}`,
188-
};
189-
}
190-
return curfile;
191-
})
192-
);
193-
}
167+
setIsLoading(false);
168+
setalertDetails({
169+
showAlert: true,
170+
alertType: 'error',
171+
alertMessage: 'Error Occurred',
172+
});
173+
setFilesData((prevfiles) =>
174+
prevfiles.map((curfile) => {
175+
if (curfile.name == file.name) {
176+
return {
177+
...curfile,
178+
status: 'Failed',
179+
type: `${file.name.substring(file.name.lastIndexOf('.') + 1, file.name.length).toUpperCase()}`,
180+
};
181+
}
182+
return curfile;
183+
})
184+
);
194185
}
195186
} else {
196187
setFilesData((prevfiles) =>
@@ -287,4 +278,4 @@ const DropZone: FunctionComponent = () => {
287278
);
288279
};
289280

290-
export default DropZone;
281+
export default DropZone;

0 commit comments

Comments
 (0)