Reputation: 89
With the query below, we can get contact's profile pictures using Microsoft Graph:
https://graph.microsoft.com/v1.0/users/{user-name}/contacts/{id}/photo/$value
Using the above query is taking a bit longer time to retrieve a large number of contacts. Is there any way to retrieve the contacts along with the profile picture in batches?
With the help the of below batch request, the contacts are fetched successfully in batches of 20(max), but for the profile photo it returns body
. I am not able to process this body
content. Is there any way out to process this body
into image
format which can be processed.
Any C# API, if there, will be much helpful.
Below is the response. The body
content is not of much help. How to process it?
Upvotes: 2
Views: 881
Reputation: 12153
The body
here is the content of a photo but base64 encoded. You can save it as a file directly.
This is my demo data from Graph API response :
Use the c# code below to save it as an image :
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var imgBody = "<body value here>";
byte[] bytes = Convert.FromBase64String(imgBody);
using (Image image = Image.FromStream(new MemoryStream(bytes)))
{
image.Save("d:/test.jpg", ImageFormat.Jpeg);
}
}
}
}
Upvotes: 1