Created
April 13, 2021 23:30
-
-
Save Lvcios/97cf3309acc755b87c3d744f99066c2a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ( | |
| <div> | |
| <form onSubmit={this.sendFile}> | |
| <input type="file" name="file" onChange={e => this.setState({ file: e.target.files[0] })} /> | |
| <button type="submit">Enviar</button> | |
| </form> | |
| </div> | |
| ); | |
| } | |
| } | |
| export default Home; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment