邮件大(> 4mb)文件附件

时间:2018-02-06 23:35:45

标签: microsoft-graph

Large (> 4mb) File Attachments类似,我想创建并发送带有>的电子邮件。通过Graph API提供4MB文件附件。使用参考附件也不是一种选择。

我已经在Uservoice上要求这个以防万一(https://officespdev.uservoice.com/forums/224641-feature-requests-and-feedback/suggestions/14158095-graph-sdk-upload-limit-should-be-higher)。

我应该尝试其他解决方法吗?

1 个答案:

答案 0 :(得分:-1)

如您所见here,您必须使用 referenceAttachment资源类型

您还可以通过单驱动器API上传文件。

让我们深入了解解决方案:

  
      
  1. 创建上传会话
  2.   
  3. 在该上传会话中,迭代地上传字节范围(每次最多4 MB),直到文件的所有字节都上传完毕为止,   并将文件附加到指定的邮件上
  4.   
  5. 保存附件的ID,以供将来访问
  6.   
  7. 可选:删除上传会话
  8.   
// Step 1: Create an upload session

const options = {
    authProvider,
};

const client = Client.init(options);

const uploadSession = {
  AttachmentItem: {
    attachmentType: "file",
    name: "flower", 
    size: 3483322
  }
};

let res = await client.api('/me/messages/AAMkADI5MAAIT3drCAAA=/attachments/createUploadSession')
    .version('beta')
    .post(uploadSession);

// Response
{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#microsoft.graph.uploadSession",
    "uploadUrl": "https://outlook.office.com/api/beta/Users('a8e8e219-4931-95c1-b73d-62626fd79c32@72aa88bf-76f0-494f-91ab-2d7cd730db47')/Messages('AAMkADI5MAAIT3drCAAA=')/AttachmentSessions('AAMkADI5MAAIT3k0tAAA=')?authtoken=eyJhbGciOiJSUzI1NiIsImtpZCI6IktmYUNIUlN6bllHMmNI",
    "expirationDateTime": "2019-09-25T01:09:30.7671707Z",
    "nextExpectedRanges": [
        "0-"
    ]
}

// Step 2: Use the upload session to upload a range of bytes of the file

PUT https://outlook.office.com/api/beta/Users('a8e8e219-4931-95c1-b73d-62626fd79c32@72aa88bf-76f0-494f-91ab-2d7cd730db47')/Messages('AAMkADI5MAAIT3drCAAA=')/AttachmentSessions('AAMkADI5MAAIT3k0tAAA=')?authtoken=eyJhbGciOiJSUzI1NiIsImtpZCI6IktmYUNIUlN6bllHMmNI
Content-Type: application/octet-stream
Content-Length: 2097152
Content-Range: bytes 0-2097151/3483322

{
  <bytes 0-2097151 of the file to be attached, in binary format>
}


// Step 3: Continue uploading byte ranges until the entire file has been uploaded

PUT https://outlook.office.com/api/beta/Users('a8e8e219-4931-95c1-b73d-62626fd79c32@72aa88bf-76f0-494f-91ab-2d7cd730db47')/Messages('AAMkADI5MAAIT3drCAAA=')/AttachmentSessions('AAMkADI5MAAIT3k0tAAA=')?authtoken=eyJhbGciOiJSUzI1NiIsImtpZCI6IktmYUNIUlN6bllHMmNI
Content-Type: application/octet-stream
Content-Length: 1386170
Content-Range: bytes 2097152-3483321/3483322

{
  <bytes 2097152-3483321 of the file to be attached, in binary format>
}


// Step 4 (optional): Get the file attachment from the message
GET https://graph.microsoft.com/api/v1.0/Users('a8e8e219-4931-95c1-b73d-62626fd79c32@72aa88bf-76f0-494f-91ab-2d7cd730db47')/Messages('AAMkADI5MAAIT3drCAAA=')/Attachments('AAMkADI5MAAIT3drCAAABEgAQANAqbAe7qaROhYdTnUQwXm0=')?$select=lastModifiedDateTime,name,contentType,size,isInline,contentId,contentLocation