繁体   English   中英

Angular 6 表单数据

[英]Angular 6 formdata

我正在使用 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);
    }

和表单数据

 let formData: FormData = new FormData();
                     formData.append(file.name,file);
                    // formData.append('StudentId',this.StudentID);
                    debugger;
                    this._ClientService.UpdateLogoprofile(data).subscribe(
                        image => {

问题:我无法在 API 中formData

更改文件追加行

formData.append('key', file);

请更正这一行

this._ClientService.UpdateLogoprofile(data)

this._ClientService.UpdateLogoprofile(formData);

同样在标题内容类型应该是 'content-type': 'multipart/form-data'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM