Skip to content

Instantly share code, notes, and snippets.

@Eth3rnit3
Created September 4, 2019 21:46
Show Gist options
  • Save Eth3rnit3/73663d2861d4f756b6d9d34de88cf9c0 to your computer and use it in GitHub Desktop.
Save Eth3rnit3/73663d2861d4f756b6d9d34de88cf9c0 to your computer and use it in GitHub Desktop.
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