work-on-file-upload

This commit is contained in:
2023-05-12 19:01:16 +05:30
parent dc53ebba06
commit 6627d42cb6
9 changed files with 152 additions and 250 deletions

32
src/pages/sampleform.jsx Normal file
View File

@@ -0,0 +1,32 @@
import React from "react";
class App extends React.Component {
upload(e)
{
console.warn(e.target.files)
const files=e.target.files
const formData=new FormData();
formData.append("img", files[0])
fetch('https://management.beanstalkedu.com/items/school',{
method: 'POST',
body: formData
}
)
.then((resp)=>{
resp.json()
.then((result)=>{
console.warn("result", result)
})
})
}
render(){
return (
<div>
<div className='flex flex-col w-full'>
<label htmlFor="school_agreement" className='text-xl font-bold pt-4'>Upload School Agreement</label>
<input type="file" onChange={(e)=>this.upload(e)} name="school_agreement" id="school_agreement" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
</div>
</div>
);
}
}
export default App;