-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.js
57 lines (49 loc) · 1.23 KB
/
upload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React, { useState } from 'react';
function App() {
const [file, setFile] = useState(null);
const [data, setData] = useState([]);
const handleFileChange = (e) => {
setFile(e.target.files[0]);
};
const handleSubmit = async () => {
const formData = new FormData();
formData.append('file', file);
try {
const response = await fetch('http://localhost:4000/upload', {
method: 'POST',
body: formData,
});
if (response.ok) {
const result = await response.json();
setData(result);
} else {
console.error('Error uploading file.');
}
} catch (error) {
console.error('There was an error sending the file.', error);
}
};
return (
<div>
<input type="file" onChange={handleFileChange} />
<button onClick={handleSubmit}>Upload</button>
<table>
<thead>
<tr>
<th>Step</th>
<th>Narrative</th>
</tr>
</thead>
<tbody>
{data.map((item, index) => (
<tr key={index}>
<td>{item.step}</td>
<td>{item.narrative}</td>
</tr>
))}
</tbody>
</table>
</div>
);
}
export default App;