I am using Microsoft Graph API to retrieve the user profile image and I want to save the retrieved image as an attachment in the list item. So I am using following code.
var response = await httpClient.GetAsync("https://graph.microsoft.com/v1.0/me/photo/$value");
var responsImage = response.Content.ReadAsStringAsync().Result;
Here, in responseImage
I am able to get image content type. So I tried saving the image to my local drive using following code:
using (Stream responseStream = responsImage)
{
using (FileStream fs = new FileStream(@"D:\image.jpg", FileMode.Create))
{
await responseStream.CopyToAsync(fs);
}
}
After saving it to my local drive for testing the image, it gives me the proper image.
Now, I am trying to save the same image as an attachment as I am having an image in Stream
object.
For saving image as an attachment I am using the code from here.
It saves the content as an attachment.
But when I open the attachment, it shows me the blank image instead of the correct image. As shown below:
I am not able to figure it out while saving its giving perfect image while using the same stream it saves the blank image.
What I am doing wrong?.