javascript - Angular 7 和 FormData
问题描述
我有角度和formData的问题。当我尝试使用 formData.get('name') 时,我收到消息:“对象 [object formData] 没有方法获取”
有人知道为什么会这样
我现在不知道改变这个的另一种方法
page.html
<ion-item>
<ion-input type="file" accept="image/*" (change)="onFileSelected($event)" id="profilePhotoFileUpload"></ion-input>
</ion-item>
页面.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] 没有获取方法”
解决方案
推荐阅读
- c - 无法将参数传递给自写函数
- spring - Spring RequestMapping Controller 注解并在同一个Controller内创建不同的绝对路径
- sql-server - 从 SQL Server 执行 Oracle 11g 函数并将结果插入 SQL 表
- javascript - Javascript如何区分mouseDown、click和doubleClick事件
- laravel - 在 Laravel 7 中使用观察者测试模型
- string - 来自字符串的 Delphi Hash - 小菜一碟?
- pine-script - 一开始就声明变量
- javascript - 通过 React 功能组件将功能从父级传递给子级
- python - 如何将多个 .npy 文件加载到单个 numpy 数组中
- django - ModelForm 没有将任何数据保存到数据库 - Django