我对angular和formData有问题。 当我尝试使用formData.get('name')时,收到消息:“对象[object formData] no具有方法get”
有人知道为什么会发生这种情况
我现在不讨论另一种更改此方法的方法
page.html
<ion-item>
<ion-input type="file" accept="image/*" (change)="onFileSelected($event)" id="profilePhotoFileUpload"></ion-input>
</ion-item>
page.ts
onFileSelected(event){
this.selectedFile = <File>event.target.files[0];
this.onUpload(this.selectedFile)
}
onUpload(selectedFile: File){
//let fd: FormData = new FormData();
var fd = new FormData();
fd.append('imageFile', this.selectedFile, this.selectedFile.name);
const httpOptions = {
headers: new HttpHeaders({
'X-Parse-Application-Id': 'JrFPfCeUABVCCDcmP2B2vaaghMIStiFmY9mz6Gv5',
'X-Parse-REST-API-Key': 'VgSHmRKTBamNL5VKUS2qYv7rL5awKprx4iigwDaf'
})
};
this.http.post(`${this.serverURL}files/myImage.png`,fd.get('imageFile'),httpOptions).subscribe(
res =>{
const object = {
name: "TestUpload",
file:{
url: res["url"],
name: res["name"],
__type:"File"
}
}
this.http.post(`${this.serverURL}/classes/User`,object,httpOptions).subscribe(res1=>{
alert(JSON.stringify(res1));
});
}
);
}
“对象[object formData]否具有方法get”