From 81e22267dfddca85e9e515ce7683efa9c8541ac8 Mon Sep 17 00:00:00 2001 From: therealbobo Date: Mon, 14 Sep 2020 18:49:09 +0200 Subject: initial upload support --- frontend/src/views/Upload.js | 106 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 frontend/src/views/Upload.js (limited to 'frontend/src/views/Upload.js') diff --git a/frontend/src/views/Upload.js b/frontend/src/views/Upload.js new file mode 100644 index 0000000..522afe8 --- /dev/null +++ b/frontend/src/views/Upload.js @@ -0,0 +1,106 @@ +import React, {Component} from 'react'; +import './Upload.scss'; +import {Button, ButtonGroup, Col, Container, Form, FormControl, InputGroup, Modal, Row, Table} from "react-bootstrap"; +import bsCustomFileInput from 'bs-custom-file-input' +import {createCurlCommand} from '../utils'; + +class Upload extends Component { + + constructor(props) { + super(props); + + this.state = { + selectedFile: null, + errors: "" + }; + + } + + onFileChange = event => { + this.setState({ selectedFile: event.target.files[0] }); + + }; + + componentDidMount() { + bsCustomFileInput.init() + } + + onFileUpload = () => { + const formData = new FormData(); + formData.append( + "file", + this.state.selectedFile, + this.state.selectedFile.name + ); + fetch('/api/pcap/upload', { + method: 'POST', + body: formData + }) + .then(response => { + if (response.status === 202 ){ + //this.setState({showConfig:false}); + this.props.onHide(); + //this.props.onDone(); + } else { + response.json().then(data => { + this.setState( + {errors : data.error.toString()} + ); + }); + } + } + ); + } + + + render() { + + return ( + + + + /usr/bin/upload + + + + + + + + +
+ +
+ {this.state.errors + .split('\n').map((item, key) => { + return {item}
}) + } +
+
+
+
+
+ + + + + +
+ ); + } +} + +export default Upload; -- cgit v1.2.3-70-g09d2