Here is a snippet of the code used for uploading form data. Although I am able to post the form data to the API, I am facing difficulties with uploading the file.
admin.component.ts
private onFileChange(event: any) {
// let reader = new FileReader();
console.log("in file change method");
if (event.target.files && event.target.files.length > 0) {
this.file = event.target.files[0];
console.log(event.target.files);
}
}
private onSubmit(userform: any) {
let _formData= new FormData();
console.log(userform.value);
userform.value.IdpMetadataFile = this.file;
console.log(userform.IdpMetadataFile)
console.log('formData', userform.value);
this._adminServices.saveAdminConfig(userform.value).subscribe(response => {
console.log(response);
this.saveAdmin = true;
});
console.log("save admin " + this.saveAdmin);
}
....admin.component.html...
<div class="form-group">
<p>Browse IDP Metadata file</p>
<input type="file" name="IdpMetadataFile " id="IdpMetadataFile " (change)="onFileChange($event)" [(ngModel)]="ViewAdminConfigData.IdpMetadataFile "
#idpMetaFileName="ngModel">
<br>