so I registered my app and got my client_id and client_secret. i setup my options and tried to upload an image but i keep getting 401 status with message "Authentication required". tried my code with get and successfully retrieved an image. error's only happening when I try to post an image". kept searching for an answer but everyone was missing their client_id in a header and as you can see - I got mine.
uploadImage(formData): Observable<object> {
const options = {
headers: new HttpHeaders({
Authorization: 'Client-ID <My_Client_ID>' // string here, replaced it for this question
}),
'mimeType': 'multipart/form-data',
'contentType': false,
'data': formData
};
return this.httpClient.post('https://api.imgur.com/3/image', options).pipe(map((res) => {
console.log(res);
return res;
}));
i am not sure what else I can do... i used my client_id in postman and it works there.
You are using the post method which accepts data as the 2nd parameter and options as the 3rd parameter. But you have passed options in place of the data parameter. Do this instead
uploadImage(formData): Observable<object> {
const options = {
headers: new HttpHeaders({
Authorization: 'Client-ID <My_Client_ID>'
}),
'mimeType': 'multipart/form-data',
'contentType': false,
};
return this.httpClient.post('https://api.imgur.com/3/image', formData, options)
.pipe(tap(console.log));
}
Also, you can perform a trivial console.log
using the tap
operator, which is the go to for side-effects.