Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

upload file in react

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>)
Comment

upload file react onclick

<input type="file" id="file" ref="fileUploader" style={{display: "none"}} />
Comment

how to upload file with button react

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' />
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery get parameter from url 
Javascript :: create video playlist using jquery 
Javascript :: copy on clip board 
Javascript :: check null or undefined in javascript 
Javascript :: move last element of array to beginning javascript 
Javascript :: represent body in javascript 
Javascript :: momentum 
Javascript :: mdn trim 
Javascript :: express-rate-limit nodejs 
Javascript :: js get last n elements of array 
Javascript :: react routes multiple compoenents 
Javascript :: java script hash 
Javascript :: how to loop over an array in js 
Javascript :: concat js 
Javascript :: javascript new date undefined 
Javascript :: autocannon npm 
Javascript :: get string length js 
Javascript :: javascript zoom image onclick 
Javascript :: create a react app 
Javascript :: js how to have an onclick inside of another onClick 
Javascript :: check file name in url 
Javascript :: call a function 
Javascript :: toggle button in angularjs bootstrap 
Javascript :: apply() js 
Javascript :: scroll js 
Javascript :: fsm2regex 
Javascript :: for of loop ecmascript 6 
Javascript :: querySelectorAll multiple lists 
Javascript :: how to disable security in jhipster 
Javascript :: js insert a point each three digit 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =