import React, {Component} from 'react'; import './Upload.scss'; import {Button, ButtonGroup, ToggleButton, Col, Container, Form, FormFile, 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, removeOriginal: false, flushAll: false, errors: "" }; this.flushAllChanged = this.flushAllChanged.bind(this); this.removeOriginalChanged = this.removeOriginalChanged.bind(this); } flushAllChanged() { this.setState({flushAll: !this.value}); this.checked = !this.checked; this.value = !this.value; } removeOriginalChanged() { this.setState({removeOriginal: !this.value}); this.checked = !this.checked; this.value = !this.value; } onLocalFileChange = event => { this.setState({ selectedFile: event.target.value }); }; onFileChange = event => { this.setState({ selectedFile: event.target.files[0] }); }; componentDidMount() { bsCustomFileInput.init() } onFileProcess = () => { const data = { "file": this.state.selectedFile, "flush_all": this.state.flushAll, "delete_original_file": this.state.removeOriginal}; fetch('/api/pcap/file', { method: 'POST', body: JSON.stringify(data) }) .then(response => { if (response.status === 202 ){ this.props.onHide(); } else { response.json().then(data => { this.setState( {errors : data.error.toString()} ); }); } } ); } 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/load_pcap --local --upload
this.removeOriginalChanged()} > --remove-original-file this.flushAllChanged()} > --flush-all



{this.state.errors .split('\n').map((item, key) => { return {item}
}) }
); } } export default Upload;