Uploading image to assets


#1

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:

wwwwwwwww

What’s wrong with my approach?


#2

I don’t know, but this is how I do it in angular: https://github.com/Squidex/squidex/blob/f0de880f8ff5a3cd98f2b92e5106c3576e365496/src/Squidex/app/shared/services/assets.service.ts#L149

The only difference I see is the accept header.