I am having a problem attaching a large file in Graph API

天大地大妈咪最大 提交于 2020-12-01 13:31:18

问题


I am attempting to attach large files using the following steps, following these guidelines: https://docs.microsoft.com/en-us/graph/outlook-large-attachments?tabs=http

Here are my steps:

  1. Create the message - https://graph.microsoft.com/v1.0/users/me/messages - this returns a message ID. To my knowledge, this is the only way to generate a messageId

  2. create an upload session - https://graph.microsoft.com/beta/users/{me}/messages/{messageId}/attachments/createUploadSession - this provides a link to the staging location

  3. (send attachment content to staging location in chunks)

  4. send the message - https://graph.microsoft.com/v1.0/users/{me}/messages/{messageid}/send

The problem occurs when the file is large enough (7mb in my case) I get 413 error on the Create Message call, saying the request is to big:

{
  "error": {
    "code": "BadRequest",
    "message": "The maximum request length supported is 4MB.",
    "innerError": {
      "date": "2020-07-19T15:35:11",
      "request-id": "17a54484-1ca6-4836-b5a1-c0d4dfbc2a30"
    }
  }
}

I have tried to work around this by "redacting" the attachment contents with a smaller number of bytes, then uploading the true contents and adding the link to the email body, but the result of this is Graph API uses the content provided in the Create Message step.

I have also tried to create the message without the attachments, obtain a message Id and then add the attachments using https://graph.microsoft.com/v1.0/users/{me}/messages/{messageId}/attachments, but this results in the following error:

{
  "error": {
    "code": "UnableToDeserializePostBody",
    "message": "were unable to deserialize ",
    "innerError": {
      "date": "2020-07-19T15:06:42",
      "request-id": "57ed5609-d0c9-4e2a-ab21-f3b753db0909"
    }
  }
}

and I have gotten this using the example request body provided here: https://docs.microsoft.com/en-us/graph/api/message-post-attachments?view=graph-rest-1.0&tabs=http

This combination of problems has made it unable for me to include large file attachments, and I could use some help. I have been required by the business to use Graph API, so don't bother suggesting other means of accomplishing this. Any help would be appreciated. I attempting to do this in a c sharp function app, but this doesn't really matter, since I can produce all of this using Postman. Let me know if any more information is needed. Thanks again!

来源:https://stackoverflow.com/questions/62982458/i-am-having-a-problem-attaching-a-large-file-in-graph-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!