【发布时间】:2016-10-12 06:54:32
【问题描述】:
当通过 REST 从当前用户的配置文件中获取 URL 时,更新 src 时图像标签无法显示:
<img id="escMyPic" src="" alt="" />
<script type="text/javascript">
$.ajax({
url: strURL + "/_api/sp.userprofiles.peoplemanager/getmyproperties",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: MyPictureSucceeded,
error: MyPictureFailed
});
function MyPictureSucceeded(data) {
if(data.d.PictureUrl != null) {
$('#escMyPic').attr('src', data.d.PictureUrl);
}
}
function MyPictureFailed() {
alert('Error: Unexpected error loading profile picture.');
}
</script>
返回 URL 在 SharePoint Online 中如下所示: https://tenant-my.sharepoint.com:443/User%20Photos/Profile%20Pictures/email_address_MThumb.jpg?t=63601764394
使用浏览器开发工具,您会看到返回的 mime 类型不是 image/jpg 而是 text/plain。我已经删除了查询字符串参数,甚至将硬编码的 URL 放在了图像标签 src 中,但它就是不显示。开发工具中的响应正文也是空白的。它似乎在显示之前进行了重定向和身份验证。
将硬编码的URL放在浏览器地址栏时,图片显示正常,开发工具响应头显示图片为URL内容,MIME类型为image/jpg。
如何从 REST 调用中显示个人资料图片?
【问题讨论】:
标签: sharepoint sharepoint-2013 office365 office365-apps office365-restapi