I need to update the profile picture by uploading it from local and then update it using the MICROSOFT GRAPH API, I tried the below code
<input type="file" accept=".jpg, .jpeg, .png"(change)="uploadImage($event.target.files)">
uploadImage(files) {
let file = files[0];
if (file) {
this.getBase64(file).then(data => {
const headers = new Headers({
'content-Type': 'image/jpeg',
'Authorization': 'Bearer ' + token
});
const options = new RequestOptions({ headers: headers });
this._http.patch('https://graph.microsoft.com/v1.0/me/photo/$value', data, options)
.subscribe(res => {});
});
}
}
getBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = error => reject(error);
});
}
I get the following error
{
"error": {
"code": "ErrorInternalServerError",
"message": "An internal server error occurred. The operation failed., The value is set to empty\r\nParameter name: smtpAddress",
"innerError": {
"request-id": "2532c086-a844-4d80-87e8-ad96545396c4",
"date": "2018-03-15T11:38:33"
}
}
}
It is based on the doc https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/profilephoto_update
How do I update the profile using Microsoft Graph API from my Angular App, how the Binary Data for Image can be obtained. Thanks in advance