当前位置:网站首页>ts+fetch实现选择文件上传
ts+fetch实现选择文件上传
2022-06-10 23:20:00 【陈小浩同学】
上传类型:File: (binary)
请求头:content-type: multipart/form-data;
html部分
<input id="updateImg" type="file"/>
js代码部分
const updateImg = document.querySelector<HTMLInputElement>("#updateImg")!;
updateImg.addEventListener('change',(e:any)=>{
const formData = new FormData();
//参数
formData.append('File',e.target.files[0]);
fetch('https://api.com/UploadImgFile', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(result => {
console.log('Success:', result);
})
.catch(error => {
console.error('Error:', error);
});
})
边栏推荐
- Several common current transformer sampling circuits
- Why is the website snapshot hijacked and tampered with
- Leetcode-15 sum of three numbers
- 【无标题】测试下啊
- 333333
- [network planning] 2.4 DNS: directory service of the Internet
- Excel cell
- array_column() expects parameter 1 to be array, array given
- [network planning] 2.5 brief introduction to P2P architecture
- [untitled]
猜你喜欢

【无标题】测试下啊

Word在目录里插入引导符(页码前的小点点)的方法

Things about Bluetooth development (1) -- starting with packet capturing data

Compared with the "South-to-North Water Transfer", what will the "east to west" of the fire bring to cloud computing?

第一章 总论-会计基础

MP framework basic operation (self use)

JVM garbage collection mechanism and common garbage collectors

VTK例子--三個相交的平面

VTK example -- three intersecting planes
![[JVM] class loading mechanism](/img/62/24b6fbec273b5cbf2338b6f4b6fe6a.png)
[JVM] class loading mechanism
随机推荐
【数据库】Nosql数据库的种类
Computer screen recording free software GIF and other format videos
String time sorting, sorting time format strings
452. detonate the balloon with the minimum number of arrows
Go语言Channel理解使用
Why is the website snapshot hijacked and tampered with
When leaving the web page, the website displays 404 Not found- starze V Club
[database] types of NoSQL database
Njupt Nanyou Discrete Mathematics_ Experiment 3
基于华为云ECS的目标检测与识别的昇腾AI开发体验【华为云至简致远】
安全培训管理办法
JVM garbage collection mechanism and common garbage collectors
Pseudo static setting of Typecho - starze V Club
[no title] 4555
sql 语句--输入 月份 查日期(年月日),输出 月份
Njupt Nanyou Discrete Mathematics_ Experiment 2
Things about Bluetooth development (1) -- starting with packet capturing data
市值215亿,这个四川80后会让电视机成为历史?
Bluetooth development (8) -- avdtp connection process
Leetcode-209 minimum length subarray