2

I am attempting to do step 1 in C#, according to Attach large files to Outlook messages as attachments from the Microsoft Graph documentation.

The GraphServiceClient and message id I'm using works fine when uploading small attachments. When uploading large attachments, however, I received this error:

The OData request is not supported.

Based on my code below, I believe I have followed the documentation correctly.

Does anyone have any idea why I would get the error message I do?

var attachmentItem = new AttachmentItem
{
    AttachmentType = AttachmentType.File,
    Name = file.Name,
    Size = file.Length //3.5MB test file
};

UploadSession session = await GraphAPIConnection.GraphClient
    .Me
    .Messages[message.Id]
    .Attachments
    .CreateUploadSession(attachmentItem)
    .Request()
    .PostAsync();

I have validated that the file, message, and attachmentItem properties have all been created properly prior to attempting the call.

Using Packages:

  • Microsoft.Graph.Core.1.20.0
  • Microsoft.Graph.Beta.0.12.0-preview

UPDATE 1:

I discovered that my endpoint when creating my GraphServiceClient was using v1.0 rather than beta. Upon changing it, I was met with the following error further into my code:

InvalidAudience

using (Stream fileStream = System.IO.File.OpenRead(file.FullName))
{
  if (session != null)
  {
    int maxSizeChunk = (320 * 1024) * 4;
    List<Exception> exceptions = new List<Exception>();
    byte[] readBuffer = new byte[maxSizeChunk];

    ChunkedUploadProvider uploadProvider = 
        new ChunkedUploadProvider
        (session, GraphAPIConnection.GraphClient, fileStream, maxSizeChunk);

    IEnumerable<UploadChunkRequest> chunkRequests = 
        uploadProvider
        .GetUploadChunkRequests();

    foreach (UploadChunkRequest request in chunkRequests)
    {
      UploadChunkResult result = 
          await uploadProvider
          .GetChunkRequestResponseAsync
          (request, readBuffer, exceptions);
      //ERROR HERE
    }
  }
}

My impression is that Graph does not need to use the alternative Outlook API. Yet, the upload session seems to use it regardless:

request.RequestUrl: https://outlook.office.com:443/api/beta/...

request.Client.BaseUrl: https://graph.microsoft.com/beta

Does this mean that I need additional scopes to properly access that API?

Do I need to generate a new client just to do so?

nmvision
  • 89
  • 1
  • 1
  • 9

0 Answers0