<input type="file" id="fileInput" name="fileInput" onChange={()=>formdate("fileInput")} accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/>
function formdate(id){
document.getElementById(id).addEventListener('change', uploadFile, false);
function uploadFile(e){
console.log(e.target.files[0]);
var file = e.target.files[0];
var formData = new FormData(id,file);
formData.append('name',attribute)
var xhr = new XMLHttpRequest();
xhr.open('POST', 'url', true);
xhr.send(formData);
}
网友评论