I am trying to upload image to assets
folder, I was successful in POSTMAN
.
But couldn’t able to do with the code.Below is my code:
component code
public uploadImage(event: any) {
if (event.target.files && event.target.files[0]) {
const reader = new FileReader();
reader.readAsDataURL(event.target.files[0]);
reader.onload = (event: any) => {
this.url = event.target.result;
this.upLoadToSquidex(this.url);
};
}
}
public upLoadToSquidex(url) {
this.appService.updateImage(url).subscribe(
(resp: any) => {
console.log(resp);
},
(error: string) => {
console.log(error);
},
);
}
service file
public updateImage(image: File): Observable<object> {
const fd = new FormData();
fd.append('file', image);
const baseUrl = `http://............./api/apps/......./assets`;
let headers = new HttpHeaders();
headers = headers.set('Authorization', this.authKey);
headers = headers.set('Accept', 'multipart/form-data');
return this.http.post(baseUrl , fd , { headers });
}
I am getting below errors:
What’s wrong with my approach?