|
1 | 1 | import React, { useState, useEffect } from "react";
|
2 | 2 | import "antd/dist/antd.css";
|
3 |
| - |
4 | 3 | import axios from "axios";
|
5 |
| - |
6 |
| -import { |
7 |
| - |
8 |
| - Card, |
9 |
| - Button, |
10 |
| - Modal, |
11 |
| - |
12 |
| -} from "antd"; |
13 |
| - |
14 |
| -import FileInput from './FileInput.tsx' |
| 4 | +import { Card, Button, Modal } from "antd"; |
| 5 | +import FileInput from './FileInput' |
15 | 6 |
|
16 | 7 |
|
17 | 8 | function UploadAlt() {
|
18 | 9 |
|
19 | 10 | const [fileData, setfileData] = useState();
|
20 |
| - |
| 11 | + const [isModalVisible, setIsModalVisible] = useState(false); |
21 | 12 | const [fileDataContent, setfileDataContent] = useState(" ");
|
22 | 13 |
|
23 | 14 | function fileContent(file) {
|
24 | 15 | setfileData(file[0]);
|
25 | 16 | // console.log(file[0]);
|
26 | 17 | }
|
27 | 18 |
|
28 |
| - |
29 |
| - |
30 |
| - return ( |
| 19 | + |
| 20 | + const handleSubmit = (e) => { |
| 21 | + const fr = new FileReader(); |
| 22 | + fr.onload = function (e) { |
| 23 | + // e.target.result should contain the text |
| 24 | + const text = e.target.result; |
| 25 | + setfileDataContent(text); |
| 26 | + console.log(fileDataContent); |
| 27 | + }; |
| 28 | + fr.readAsText(fileData); |
| 29 | + axios({ |
| 30 | + method: "post", |
| 31 | + url: "", |
| 32 | + // database table with the columns Name, content |
| 33 | + data: [{ Name: fileData.name, content: fileDataContent }] |
| 34 | + }) |
| 35 | + .then(function (response) { |
| 36 | + // handle success |
| 37 | + console.log(response.data); |
| 38 | + }) |
| 39 | + .catch(function (error) { |
| 40 | + // handle error |
| 41 | + console.log(error); |
| 42 | + }); |
| 43 | + }; |
| 44 | + |
| 45 | + return ( |
31 | 46 | <div>
|
32 | 47 | <Card
|
33 | 48 | style={{
|
34 | 49 | paddingTop: "40px",
|
35 | 50 | width: 386,
|
36 | 51 | paddingBottom: "20px",
|
37 | 52 | marginBottom: "20px"
|
38 |
| - }} |
39 |
| - > |
| 53 | + }}> |
40 | 54 | <FileInput fileContent={fileContent} />
|
41 |
| - |
42 |
| - |
| 55 | + <Button type="primary" onClick={showModal} style={{marginTop: "50px"}}> |
| 56 | + Upload |
| 57 | + </Button> |
| 58 | + |
43 | 59 | </Card>
|
44 | 60 | </div>
|
45 | 61 | );
|
46 | 62 | }
|
47 |
| - |
48 | 63 | export default UploadAlt;
|
0 commit comments