Мой фронт-сервер Angular6
BackServer экспресс
Когда я пытаюсь опубликовать форм-данные на backserver
Файл успешно загружен.
Ноя получаю эту ошибку
SyntaxError: Unexpected token U in JSON at position 0
at JSON.parse (<anonymous>)
at XMLHttpRequest.onLoad (webpack-internal:///./node_modules/@angular/common/esm5/http.js:2289:51)
at ZoneDelegate.invokeTask (webpack-internal:///./node_modules/zone.js/dist/zone.js:421:31)
at Object.onInvokeTask (webpack-internal:///./node_modules/@angular/core/esm5/core.js:4967:33)
at ZoneDelegate.invokeTask (webpack-internal:///./node_modules/zone.js/dist/zone.js:420:36)
at Zone.runTask (webpack-internal:///./node_modules/zone.js/dist/zone.js:188:47)
at ZoneTask.invokeTask [as invoke] (webpack-internal:///./node_modules/zone.js/dist/zone.js:496:34)
at invokeTask (webpack-internal:///./node_modules/zone.js/dist/zone.js:1540:14)
at XMLHttpRequest.globalZoneAwareCallback (webpack-internal:///./node_modules/zone.js/dist/zone.js:1566:17)
вот мой код
uploadFile() {
this.http.User_postFileData_withF('signup/upload-signup/' + this.userId, this.uploadData).subscribe(
data => {
console.log(data)
},
error => {
console.log(error)
},
() => {
console.log('upload finish')
}
);
}
http метод
User_postFileData_withF(url: string, body) {
const headers = new HttpHeaders({'Authorization': sessionStorage.getItem("userToken") });
return this.http.post(this.serverip + url, body, { headers: headers });
}
мой html
<input type="file" accept="image/*" (change)="changeFile($event)"
<button type="button" class="btn btn-primary" (click)="uploadFile()">上傳</button>
мой тс
uploadData = new FormData();
changeFile(event) {
var image = event.target.files[0];
var pattern = /image-*/;
var reader = new FileReader();
this.uploadData.append('name', image);
}
спасибо