PaNika
PaNika

Reputation: 11

Downloading multiple files from OneDrive with MS Graph batch returns zero length content

I'm trying to download multiple files from OneDrive using a MS Graph Batch (C#). The Batch response returns Status Code: 302,'Found' but the response content has zero length. Does anyone know how can I get the stream of the file(s) using MS Graph Batch? Thank you

My code:

var r1 = graphClient.Drives[DriveID()]
                .Root
                .ItemWithPath($"{MyFullPath1}")
                .Content
                .ToGetRequestInformation();

var r2 = graphClient.Drives[DriveID()]
                .Root
                .ItemWithPath($"{MyFullPath2}") // Same behavior when I use .Items[$"{myItemID}"]
                .Content
                .ToGetRequestInformation();
 // Build the batch
var batchRequestContent = new BatchRequestContentCollection(graphClient);  
var addEventRequestId = await batchRequestContent.AddBatchRequestStepAsync(r1);
var addEventRequestId2 = await batchRequestContent.AddBatchRequestStepAsync(r2); 
var batchResponse = await graphClient.Batch.PostAsync(batchRequestContent); 
var response1 = await batchResponse.GetResponseByIdAsync(addEventRequestId);
var response2 = await batchResponse.GetResponseByIdAsync(addEventRequestId2);
// This creates a byte array of zero length
myFileBytes= Convert.FromBase64String(await response.Content.ReadAsStringAsync());
System.IO.File.WriteAllBytes($"{myLocalDiskPath}", myFileBytes); 

// This creates stream of 0 length
var myStream = await response2.Content.ReadAsByteArrayAsync();

Upvotes: 0

Views: 59

Answers (0)

Related Questions