Skip to content

Instantly share code, notes, and snippets.

@fulopdaniel
Created September 6, 2018 12:36
Show Gist options
  • Save fulopdaniel/a51b8c27e864b34f0f68556414e4f0fb to your computer and use it in GitHub Desktop.
Save fulopdaniel/a51b8c27e864b34f0f68556414e4f0fb to your computer and use it in GitHub Desktop.
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