上载到imgur时出错(身份验证标头格式错误)

时间:2020-03-28 15:49:48

标签: angular imgur

我正在尝试使用Imgur在一个有角度的Web应用程序中上传一些图像,但是一直出现“格式错误的身份验证标头” ,有人知道如何解决此错误吗?

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 个答案:

答案 0 :(得分:0)

用于在Angular中设置HttpHeaders的correct way像这样:

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