Error upload to imgur (malformed auth header)

Viewed 136

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());
    }

1 Answers

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

const header = new HttpHeaders().set('Authorization', 'Client-ID xxxxxxxxxxx');
Related