我正在使用angular 6.我正在通过表单数据发送图像文件数据。但是我可以在API中获取文件数据。这是我的代码
UpdateLogoprofile(data: any): Observable<any> {
debugger;
const model = {};
const url = AppSettings.API_ENDPOINT + 'Client/UploadFileToStorage';
console.log(data);
// const body = JSON.stringify(data);
//const body = data;
const httpOptions = {
headers: new HttpHeaders({
'content-type': 'application/json',
'Authorization': 'bearer ' + this.auth_token + ''
})
};
return this.http.post(url, data, httpOptions)
// .map(this.extractData)
.map((response: Response) => <any>response.json())
.catch(this.handleError);
}
和FormData
let formData: FormData = new FormData();
formData.append(file.name,file);
// formData.append('StudentId',this.StudentID);
debugger;
this._ClientService.UpdateLogoprofile(data).subscribe(
image => {
答案 0 :(得分:0)
更改文件附加行
formData.append('key', file, file.name);
答案 1 :(得分:0)
请更正此行
this._ClientService.UpdateLogoprofile(data)
到
this._ClientService.UpdateLogoprofile(formData);
标题内容类型也应为“ content-type”:“ multipart / form-data”