I'm currently working on a project using Angular 12 and Spring Boot for image uploads. I have successfully tested the API with Postman and it's working correctly on the backend. However, when I try to test the front end, I encounter the following error:
"status: 415, error: "Unsupported Media Type", message: "Content type 'application/json' not supported","
******* Here's my TypeScript file: *******
host = environment.API_URL;
private baseUrl = this.host;
constructor(private http: HttpClient) { }
upload(file: File): Observable<HttpEvent<any>> {
const formData: FormData = new FormData();
formData.append('file', file);
const req = new HttpRequest('POST', `${this.baseUrl}/uploadFile`, formData,{
reportProgress: true,
responseType: 'json'
});
return this.http.request(req);
}
getFiles(): Observable<any> {
return this.http.get(`${this.baseUrl}/files`);
}
}
Thank you for any assistance you can provide.