1
+ import axios from 'axios' ;
1
2
import { Dropzone , Flex , Typography } from '@neo4j-ndl/react' ;
2
3
import React , { useState , useEffect , FunctionComponent } from 'react' ;
3
4
import Loader from '../utils/Loader' ;
4
5
import { v4 as uuidv4 } from 'uuid' ;
5
6
import { useCredentials } from '../context/UserCredentials' ;
6
7
import { useFileContext } from '../context/UsersFiles' ;
7
8
import CustomAlert from './Alert' ;
8
- import { CustomFile , CustomFileBase , UserCredentials , alertStateType } from '../types' ;
9
+ import { CustomFile , CustomFileBase , UploadResponse , alertStateType } from '../types' ;
9
10
import { buttonCaptions , chunkSize } from '../utils/Constants' ;
11
+ import { url } from '../utils/Utils' ;
10
12
import { InformationCircleIconOutline } from '@neo4j-ndl/react/icons' ;
11
13
import IconButtonWithToolTip from './IconButtonToolTip' ;
12
- import { uploadAPI } from '../utils/FileAPI' ;
13
14
14
15
const DropZone : FunctionComponent = ( ) => {
15
16
const { filesData, setFilesData, model } = useFileContext ( ) ;
@@ -50,7 +51,6 @@ const DropZone: FunctionComponent = () => {
50
51
type : `${ file . name . substring ( file . name . lastIndexOf ( '.' ) + 1 , file . name . length ) . toUpperCase ( ) } ` ,
51
52
size : file . size ,
52
53
uploadprogess : file . size && file ?. size < chunkSize ? 100 : 0 ,
53
- // total_pages: 0,
54
54
id : uuidv4 ( ) ,
55
55
...defaultValues ,
56
56
} ) ;
@@ -121,11 +121,14 @@ const DropZone: FunctionComponent = () => {
121
121
} )
122
122
) ;
123
123
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
+
125
130
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 } ` ) ;
129
132
} else {
130
133
if ( apiResponse . data . data ) {
131
134
setFilesData ( ( prevfiles ) =>
@@ -134,7 +137,6 @@ const DropZone: FunctionComponent = () => {
134
137
return {
135
138
...curfile ,
136
139
uploadprogess : chunkNumber * chunkProgressIncrement ,
137
- // total_pages: apiResponse.data.data.total_pages,
138
140
} ;
139
141
}
140
142
return curfile ;
@@ -162,35 +164,24 @@ const DropZone: FunctionComponent = () => {
162
164
uploadNextChunk ( ) ;
163
165
}
164
166
} 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
+ ) ;
194
185
}
195
186
} else {
196
187
setFilesData ( ( prevfiles ) =>
@@ -287,4 +278,4 @@ const DropZone: FunctionComponent = () => {
287
278
) ;
288
279
} ;
289
280
290
- export default DropZone ;
281
+ export default DropZone ;
0 commit comments