file upload using fetch react how to accces it on server side code example
Example: uploading file with fetch
const input = document.getElementById('fileinput');
const upload = (file) => {
fetch('http://www.example.net', {
method: 'POST',
headers: {
"Content-Type": "You will perhaps need to define a content-type here"
},
body: file
}).then(
response => response.json()
).then(
success => console.log(success)
).catch(
error => console.log(error)
);
};
const onSelectFile = () => upload(input.files[0]);
input.addEventListener('change', onSelectFile, false);