const upload = (e) => {
console.warn(e.target.files)
const files = e.target.files
const formData = new FormData()
formData.append('img', files[0])
fetch('http://127.0.0.1:8000/api/store', {
method: 'POST',
body: formData,
}).then((resp) => {
resp.json().then((result) => {
console.warn(result)
})
})
}
return(<div>
<h1>Upload File in React js</h1>
<input type='file' onChange={(e) => upload(e)} name='img' />
</div>)
<input type="file" id="file" ref="fileUploader" style={{display: "none"}} />
document.getElementById('buttonid').addEventListener('click', openDialog);
function openDialog() {
document.getElementById('fileid').click();
}
<input id='fileid' type='file' hidden/>
<input id='buttonid' type='button' value='Upload MB' />