当发出 GET( https://graph.microsoft.com/v1.0/users/ {{user_id}} /photo/$value) 请求时,响应数据将写入与图像相同的字符
转换为base64后,我尝试了blob格式,但图片没有出现。
路由器.js
router.get('/photo/:id',function (req,res) {
auth.getAccessToken().then(function (token){
let userId = req.params.id;
graph.getUserPhotoData(token, userId).then(function (result) {
res.json(result);
}).catch(function (e) { console.log(e) })
});
});
Run Code Online (Sandbox Code Playgroud)
图.js
function getUserPhoto(token, userId){
return axios({
method : 'get',
url : 'https://graph.microsoft.com/v1.0/users/'+{{user_id}}+'/photo/$value',
headers: {
'Authorization':token,
// 'Content-Type': 'image/jpeg',
},
responseType : 'blob'
})
}
async function getUserPhotoData(token,userId) {
try{
let userPhoto = getUserPhoto(token,userId);
let p = userPhoto.data;
// let photo = new Buffer(userPhoto.data).toString('base64');
return p; //...013O?\u0011?e????|??>?4+?y??\u0017?"Y...
}catch (e) { console.log(e);} …Run Code Online (Sandbox Code Playgroud)