2

I'm trying to use Imgur to upload some images in an angular web app, but keep getting "Malformed auth header", does anybody know how to fix this error?

async uploadImage(imageFile: File, infoObject: {}, categoryId) {
        const formData = new FormData();
        formData.append('image', imageFile, imageFile.name);

        const header = new HttpHeaders(`Authorization: Client-ID xxxxxxxxxxx`);
        const imageData = await this.http.post(this.url, formData, {headers: header}).toPromise();
        this.imageLink = imageData['data'].link;

        const newImageObject: ImageInfo = {
          title: infoObject['title'],
          description: infoObject['description'],
          link: this.imageLink
        };
        this.images.unshift(newImageObject);
        this.updateCategoryImgIconPath(categoryId, this.imageLink).subscribe(data => window.location.reload());
    }
Valy Dia
  • 2,781
  • 2
  • 12
  • 32

1 Answers1

0

The correct way to set HttpHeaders in Angular is like this:

const header = new HttpHeaders().set('Authorization', 'Client-ID xxxxxxxxxxx');
m93a
  • 8,866
  • 9
  • 40
  • 58