Lucio Flores
2021-04-13T23:30:58Z

SendFileWithReact.js

| import React from 'react';
|
| class Home extends React.Component {
|
| constructor(props) {
| super(props)
| this.state = {
| file: null
| }
| this.sendFile = this.sendFile.bind(this)
| }
|
| sendFile(event) {
| event.preventDefault();
| let formData = new FormData();
| formData.append('myFile', this.state.file);
|
| fetch('/api/uploadFile/excel', {
| method: 'POST',
| body: formData
| })
| .then(response => response.json())
| .then(data => {
| console.log(data)
| })
| .catch(error => {
| console.error(error)
| })
| }
|
| render() {
| return (
|
|
| this.setState({ file: e.target.files[0] })} />
| Enviar
|
|
| );
| }
| }
|
| export default Home;