I need some assistance in trying to figure out what I'm missing trying to send a pdf/file from angular to my backend via form-data and I am having some issues doing so I am getting errors when submit is pressed via POST (error and code attached). I would appreciate any assistance!
component.ts
handleFileInput(file: File) {
this.fileToUpload = file;
}
basicUpload(files: File){
var formData = new FormData();
formData.append('file', files)
this.execSummaryUploadService.upload(formData)
.subscribe(event => {
})
}
HTML
<div class="form-group">
<label for="file">Choose File</label>
<input type="file"
id="file"
(change)="handleFileInput($event.target.files)">
<button mat-fab color="primary" (click)="basicUpload()">Send</button>
</div>
Upload Service
constructor(private http: HttpClient) { }
public upload(formData) {
return this.http.post<any>(this.URL, formData, {
reportProgress: true,
observe: 'events'
});
}
ERROR
core.js:15714 ERROR HttpErrorResponse {headers: HttpHeaders, status: 400, statusText: "Bad Request"
Content-Typeheader on the request. const headers = new HttpHeaders({'Content-Type': 'multipart/form-data'}); return this.http.post<any>(this.URL, formData, { headers, reportProgress: true, observe: 'events' });`