-
Notifications
You must be signed in to change notification settings - Fork 263
Description
Describe the bug
After retrieving a list of users that met specific search/filter criteria, we are creating a batch request to retrieve photos for the returned users. The following code executes successfully, but the photoStream is empty likely due to the incorrect content type "application/json" instead of "image/jpeg".
We have confirmed that a similar batch request made directly against the API does in fact return the base64 string representation of the image. Additionally, attempts have been made to try and work around the problem by gaining access to the underlying NativeResponseObject, but have been unable to figure out how to leverage this for batch requests. We also tried to leverage config.QueryParameters when each request was generated to specify the format as image/jpeg, but QueryParameters in latest version of SDK does not have a Format property. Also tried to specify the Content-Type in the header of each request, but it is either ignored with batch requests or doesn't work. Are there other options/workarounds to retrieving a list of users with their photos in a performant manner?
This issue appears to be similar to what mbratukha is doing in this issue, but are using the newer GetResponseStreamByIdAsync. There is mention of the issue being fixed, but it seems to have been reintroduced with the redesign of this functionality in v5 of the SDK. It is unfortunate that this issue appears to still exist over 3 years following it being reported.
Expected behavior
GetResponseStreamByIdAsync should appropriately return a stream of the content.
How to reproduce
- Create a GraphClient
- Add a list of users to a collection where each item contains a userPrincipalName.
- Execute the following code to create a BatchRequestContentCollection and add a batch request step for each user to retrieve their photo associating a unique key, i.e. userPrincipalName, to each request.
- Post the batch request and iterate through each user in the collection issuing a call to GetResponseStreamByIdAsync to retrieve the photoStream using userPrincipalName.
- The photoStream will have a length, but each byte in the array will be 0, i.e. no Content.
var requestContent = new BatchRequestContentCollection(GraphClient);
foreach (var user in users) //user is a GraphUser
{
var photoRequest = GraphClient.Users[user.UserPrincipalName].Photo.Content.ToGetRequestInformation((config) =>
{
config.Headers.Add("Content-Type", "image/jpeg"); //Tried to see if this would help, but it doesn't
});
var photoId = await requestContent.AddBatchRequestStepAsync(photoRequest, user.UserPrincipalName);
}
var response = await GraphClient.Batch.PostAsync(requestContent);
foreach (var user in users)
{
using (var photoStream = await response.GetResponseStreamByIdAsync(user.UserPrincipalName))
{
using (var memoryStream = new MemoryStream())
{
await photoStream.CopyToAsync(memoryStream);
user.ThumbnailPhoto = memoryStream.ToArray();
}
}
}SDK Version
5.75.0
Latest version known to work for scenario above?
No response
Known Workarounds
N/A
Debug output
Click to expand log
```</details>
### Configuration
- OS: Windows 11
- architecture: x64
- Doesn't appear to be related to OS or architecture configuration
### Other information
Related to support request 2503270040016469
