在formData.append()的帮助下将文件发送到后端(附加文档详细信息)。它在google chrome中工作正常。但是我在mozila和safari中遇到了这个错误的问题。
服务代码:
manageSingleDataWithChildModel(url: string, data: any, childData: any, docRefArea: string = ''): Observable<any> {
this._spinnerService.show();
this.refreshSession();
var formData: FormData = new FormData();
formData.append('docReferenceArea', docRefArea);
childData.forEach((data: any) => {
if (data.DocumentDetails != null && data.DocumentDetails.DocContent != null && data.DocumentDetails.DocContent != "") {
data.FileIdentifier = data.DocumentDetails.FileIdentifier;
formData.append('files', data.DocumentDetails.DocContent, data.DocumentDetails.FileIdentifier);
data.DocumentDetails.DocContent = null;
}
});
formData.append('dataModel', JSON.stringify(data));
let headers = new Headers(
{
'enctype': 'multipart/form-data',
'method': 'POST',
'Authorization': 'Bearer ' + localStorage.getItem('BearerToken'),
});
let options = new RequestOptions({ headers: headers });
return this._http.post(url, formData, options)
.map((res: Response) => { this._spinnerService.hide(); return HttpHelper.json(res) })
.catch(error => this.handleError(error));
}
答案 0 :(得分:1)
docRefArea您将其指定为字符串。但它实际上是一个包含文件详细信息的对象。
通过将代码的第一行更改为
来尝试manageSingleDataWithChildModel(url: string, data: any, childData: any, docRefArea: any = ''): Observable<any> {