1 回答
TA贡献1807条经验 获得超9个赞
TALK IS CHECAP, SHOW ME THE CODE
<html>
<body>
<form>
<div>
<label>Select file to upload</label>
<input type="file">
</div>
<button id="taozhi" type="submit">Convert</button>
</form>
<script>
var p = document.getElementById("taozhi");
p.onclick = showAlert;
function showAlert(event) {
// 这就是你需要的吧!!input.files获取选中文件之后的filelist
const input = document.querySelector('input[type="file"]')
const file = input.files[0]
let formData = new FormData();
formData.append('image', file);
fetch('http://localhost:8001/upload',{
method:'post',
body:formData,
})
.then((response) => response.json() )
.then((response)=>{
console.log(response)
})
.catch((err)=>console.error(err));
}
</script>
</body>
</html>
添加回答
举报