gpt4 book ai didi

javascript - 无法使用 Microsoft Graph API 和 Angular 4 更新个人资料图片

转载 作者:行者123 更新时间:2023-11-30 20:40:44 28 4
gpt4 key购买 nike

我需要通过从本地上传来更新个人资料图片,然后使用 MICROSOFT GRAPH API 更新它,我尝试了以下代码

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

出现以下错误

{
"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"
}
}
}

它基于文档 https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/profilephoto_update

如何从我的 Angular 应用程序使用 Microsoft Graph API 更新配置文件,如何获取图像的二进制数据。提前致谢

最佳答案

您收到关于 smtpAddress 被“设置为空”的错误的原因是该用户没有 Exchange Online 邮箱。您只能向具有有效 Exchange Online 邮箱的用户上传个人资料照片。不支持具有本地邮箱或 Outlook.com 的用户。

来自documentation :

A profile photo of a user, group or an Outlook contact accessed from Exchange Online. It's binary data not encoded in base-64.

另外,您需要发送原始二进制文件,不是图像的 base64 编码表示。

关于javascript - 无法使用 Microsoft Graph API 和 Angular 4 更新个人资料图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49298572/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com