Skip to content

Instantly share code, notes, and snippets.

@berat
Created March 14, 2020 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berat/ec25021ac4a3eb4f29636173cba4a392 to your computer and use it in GitHub Desktop.
Save berat/ec25021ac4a3eb4f29636173cba4a392 to your computer and use it in GitHub Desktop.
Send image to API in React
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