Html 在4中过帐数据时出现网络错误
我在学英语。我试图发布一个带有关键字的文件。上载时,我在网页控制台中遇到以下错误 代码:19 列数:0 数据:空 文件名:“ 电话号码:5291 消息:“发生网络错误。” 名称:“网络错误” 结果:2152923155 这就是我试图上传文件的方式 .service文件中的方法Html 在4中过帐数据时出现网络错误,html,angular,typescript,angular-httpclient,Html,Angular,Typescript,Angular Httpclient,我在学英语。我试图发布一个带有关键字的文件。上载时,我在网页控制台中遇到以下错误 代码:19 列数:0 数据:空 文件名:“ 电话号码:5291 消息:“发生网络错误。” 名称:“网络错误” 结果:2152923155 这就是我试图上传文件的方式 .service文件中的方法 url: String = 'localhost:8080/file-uploader/rest/file/'; getFileName(fileToUpload: File, columnHeading
url: String = 'localhost:8080/file-uploader/rest/file/';
getFileName(fileToUpload: File, columnHeading: any) {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'multipart/form-data',
})
};
const body = {
file: fileToUpload,
columnHeading: columnHeading
};
return this.http.post<UploadResponse['path']>(this.url + 'upload', body, httpOptions);
}
interface UploadResponse {
path: string;
}
uploadFile() {
this.httpService.getFileName(this.file, this.columnHeading).subscribe(
res => {
localStorage.setItem('filePath', res);
}
);
}
<div>
<input type="file" [(ngModel)]="file" name="file">
<br>
<input type="text" [(ngModel)]="columnHeading" name="columnHeading">
<br>
<!-- (click) passes input value to add() and then clears the input -->
<button (click)="uploadFile()">
Upload File
</button>
</div>
文件上载类型脚本文件
url: String = 'localhost:8080/file-uploader/rest/file/';
getFileName(fileToUpload: File, columnHeading: any) {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'multipart/form-data',
})
};
const body = {
file: fileToUpload,
columnHeading: columnHeading
};
return this.http.post<UploadResponse['path']>(this.url + 'upload', body, httpOptions);
}
interface UploadResponse {
path: string;
}
uploadFile() {
this.httpService.getFileName(this.file, this.columnHeading).subscribe(
res => {
localStorage.setItem('filePath', res);
}
);
}
<div>
<input type="file" [(ngModel)]="file" name="file">
<br>
<input type="text" [(ngModel)]="columnHeading" name="columnHeading">
<br>
<!-- (click) passes input value to add() and then clears the input -->
<button (click)="uploadFile()">
Upload File
</button>
</div>
文件上载html标记文件
url: String = 'localhost:8080/file-uploader/rest/file/';
getFileName(fileToUpload: File, columnHeading: any) {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'multipart/form-data',
})
};
const body = {
file: fileToUpload,
columnHeading: columnHeading
};
return this.http.post<UploadResponse['path']>(this.url + 'upload', body, httpOptions);
}
interface UploadResponse {
path: string;
}
uploadFile() {
this.httpService.getFileName(this.file, this.columnHeading).subscribe(
res => {
localStorage.setItem('filePath', res);
}
);
}
<div>
<input type="file" [(ngModel)]="file" name="file">
<br>
<input type="text" [(ngModel)]="columnHeading" name="columnHeading">
<br>
<!-- (click) passes input value to add() and then clears the input -->
<button (click)="uploadFile()">
Upload File
</button>
</div>
上载文件
此.url的值是多少?这应该更像返回this.http.post(this.url+/upload',body,httpOptions)代码>谢谢,我将用这些值编辑问题。