Created
September 6, 2018 12:36
-
-
Save fulopdaniel/a51b8c27e864b34f0f68556414e4f0fb to your computer and use it in GitHub Desktop.
This file contains 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
handleFileUpload = (event) => { | |
this.setState({ file: event.target.files }); | |
}; | |
submitFile = (event) => { | |
event.preventDefault(); | |
const formData = new FormData(); | |
formData.append('file', this.state.file[0]); | |
axios | |
.post( | |
'https://your-api-endpoint.com/upload', | |
formData, | |
{ | |
headers: { | |
'Content-Type': 'multipart/form-data', | |
} | |
} | |
) | |
.then((response) => { | |
// handle your response | |
}) | |
.catch(() => { | |
// handle your error | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment