上传类型: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);
});
})