Created
September 4, 2019 21:46
-
-
Save Eth3rnit3/73663d2861d4f756b6d9d34de88cf9c0 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
import React from 'react' | |
import Axios from 'axios' | |
const submitForm = function (event) { | |
event.preventDefault(); | |
let formData = new FormData(event.target); | |
Axios.post('/api/v1/uploads', formData) | |
.then(res => { | |
alert(`File has been uploaded ${res.data.url}`) | |
}) | |
.catch(err => { | |
console.error(err); | |
alert('Error') | |
}) | |
} | |
export default function Uploader() { | |
return ( | |
<div> | |
<form onSubmit={submitForm}> | |
<label htmlFor="file">File input</label> | |
<input | |
type="file" | |
id="file" | |
name="upload[file]" /> | |
<button type="submit">Send file</button> | |
</form> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment