Created
March 14, 2020 09:37
-
-
Save berat/ec25021ac4a3eb4f29636173cba4a392 to your computer and use it in GitHub Desktop.
Send image to API in React
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' | |
function HomePage() { | |
const uploadImage = e => { | |
const formData = new FormData() | |
formData.append('gelinFoto', e.target.files[0]) | |
Axios.post( | |
`http://localhost:3000/upload`, | |
formData, | |
{ | |
headers: { | |
'Content-Type': 'multipart/form-data' | |
} | |
} | |
).then(response => {}) | |
} | |
return ( | |
<div | |
<input | |
accept=".png,.jpg,.jpeg" | |
type="file" | |
onChange={uploadImage} | |
/> | |
</div> | |
) | |
} | |
export default HomePage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment