Skip to content

Instantly share code, notes, and snippets.

@Eth3rnit3
Created September 4, 2019 21:46
Show Gist options
  • Save Eth3rnit3/96baf7f817873ec60b833834321af010 to your computer and use it in GitHub Desktop.
Save Eth3rnit3/96baf7f817873ec60b833834321af010 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);
console.log(formData.get('upload[file]'))
Axios.post('/api/v1/uploads', formData)
.then(res => {
console.log(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