gpt4 book ai didi

microsoft-graph-api - 带有大(> 4mb)文件附件的邮件

转载 作者:行者123 更新时间:2023-12-02 15:52:25 25 4
gpt4 key购买 nike

类似于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 )。

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

最佳答案

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

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

让我们深入研究解决方案:

  1. Create an upload session
  2. Within that upload session, iteratively upload ranges of bytes (up to 4 MB each time) until all the bytes of the file have been uploaded, and the file is attached to the specified message
  3. Save the ID for the attachment for future access
  4. Optional: Delete the upload session
// 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

关于microsoft-graph-api - 带有大(> 4mb)文件附件的邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48653691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com