I'm trying to upload file to server but not working and I got this error..
I don't have any idea how to fix it.. This is my code..
HTML
<div class="col-lg-4">
<input type="file" class="custom-file-input" #fileUploader (change)="uploadBanner($event.target.files)">
<label class="custom-file-label" #labelImport for="importFile"></label>
<ng-container *ngIf="uploadSuccess">Upload Successful</ng-container>
Component
uploadBanner(files : File){
let data={
Id: this.confId,
file: files[0].name,
type: "Banner"
}
this.httpService.upload(data).subscribe(event =>{
if (event.type === HttpEventType.DownloadProgress) {
this.percentDone = Math.round(100 * event.loaded / event.total);
} else if (event instanceof HttpResponse) {
this.uploadSuccess = true;
}
});
}
Service
public upload(file: File): Observable<HttpEvent<any>> {
const formData: FormData = new FormData();
formData.append('file', file);
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
Authorization: 'Bearer '+this.getToken()
})
};
var header = {
responseType: 'json',
reportProgress: true,
};
return this.httpClient.post<any>(this.serverUrl + this.basePath + '/upload',{formData,header,httpOptions});
}