Skip to content

Commit 1a58698

Browse files
authored
Merge pull request #8 from jackisgood13/jackisgood13
Update UploadAlt
2 parents 9340863 + 2c8efa1 commit 1a58698

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

src/UploadAlt.tsx

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,63 @@
11
import React, { useState, useEffect } from "react";
22
import "antd/dist/antd.css";
3-
43
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'
156

167

178
function UploadAlt() {
189

1910
const [fileData, setfileData] = useState();
20-
11+
const [isModalVisible, setIsModalVisible] = useState(false);
2112
const [fileDataContent, setfileDataContent] = useState(" ");
2213

2314
function fileContent(file) {
2415
setfileData(file[0]);
2516
// console.log(file[0]);
2617
}
2718

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 (
3146
<div>
3247
<Card
3348
style={{
3449
paddingTop: "40px",
3550
width: 386,
3651
paddingBottom: "20px",
3752
marginBottom: "20px"
38-
}}
39-
>
53+
}}>
4054
<FileInput fileContent={fileContent} />
41-
42-
55+
<Button type="primary" onClick={showModal} style={{marginTop: "50px"}}>
56+
Upload
57+
</Button>
58+
4359
</Card>
4460
</div>
4561
);
4662
}
47-
4863
export default UploadAlt;

0 commit comments

Comments
 (0)