Rest Gmail Api可恢复上传休息(附件大于5MB)

Rest Gmail Api可恢复上传休息(附件大于5MB),rest,attachment,gmail-api,Rest,Attachment,Gmail Api,我试图通过Gmail Api Rest发送附件大于5MB的邮件。为了实现这一点,我正试图将其与可恢复上传一起发送。这是我的密码 byte[] ba = System.IO.File.ReadAllBytes(uploadFromPath); String base64String = Convert.ToBase64String(ba); string url = "https://www.googleapis.com/upload/gmail/v1/users/me/messages/send

我试图通过Gmail Api Rest发送附件大于5MB的邮件。为了实现这一点,我正试图将其与可恢复上传一起发送。这是我的密码

byte[] ba = System.IO.File.ReadAllBytes(uploadFromPath);
String base64String = Convert.ToBase64String(ba);
string url = "https://www.googleapis.com/upload/gmail/v1/users/me/messages/send?uploadType=resumable"
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Headers.Add("Authorization", "Bearer " + token);
request.Headers.Add("X-Upload-Content-Type", "message/rfc822");
request.Headers["X-Upload-Content-Length"]= base64String.Length.ToString();
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = body.Length;
在我提出请求后,我得到了位置

location = res.Headers["Location"];
然后我用位置发出PUT请求

我想知道我应该在第一个请求正文中插入什么,在第二个请求正文中应该插入什么。 我看过这篇文章
但该代码仅适用于小于5MB的文件。要实现大于5MB的连接,我还需要做些什么吗?

文档上确实有样本

步骤1:启动可恢复会话 可恢复会话启动请求

POST /upload/gmail/v1/users/userId/messages/send?uploadType=resumable HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer your_auth_token
Content-Length: 38
Content-Type: application/json; charset=UTF-8
X-Upload-Content-Type: message/rfc822
X-Upload-Content-Length: 2000000

{
  "id": string,
  "threadId": string,
  "labelIds": [
    string
  ],
  "snippet": string,
  "historyId": unsigned long,
  "payload": {
    "partId": string,
    "mimeType": string,
    "filename": string,
    "headers": [
      {
        "name": string,
        "value": string
      }
    ],
    "body": users.messages.attachments Resource,
    "parts": [
      (MessagePart)
    ]
  },
  "sizeEstimate": integer,
  "raw": bytes
}
步骤2:保存可恢复会话URI

HTTP/1.1 200 OK
Location: https://www.googleapis.com/upload/gmail/v1/users/userId/messages/send?uploadType=resumable&upload_id=xa298sd_sdlkj2
Content-Length: 0
步骤3:上传文件

PUT https://www.googleapis.com/upload/gmail/v1/users/userId/messages/send?uploadType=resumable&upload_id=xa298sd_sdlkj2 HTTP/1.1
Content-Length: 2000000
Content-Type: message/rfc822

bytes 0-1999999

如何初始化有效负载主体和部件?如果我在有效负载主体内设置了附件的数据,http主体就会变得太大,并且我会收到一个错误的请求错误。您有任何初始化http主体的实际示例吗?在第3步PUT请求中,我是否只输入在base64上转换的附件字节@努吉