首页 > 解决方案 > 如何在 microsoft graph api 中添加二进制数据以使用上传会话上传文件

问题描述

对于我的 Flutter 项目,要在草稿电子邮件中上传附件,我已经创建了上传会话,并通过它尝试上传附件。为此,从Microsoft graph官方文档中获取大文件附件,需要这样传递:

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>
}

谁能帮忙分享我们如何将二进制数据传递给请求?

标签: fluttermicrosoft-graph-apibinary-data

解决方案


您可以尝试以下代码:

$contentBytes = file_get_contents('image/image.jpg');
    $options = array(
        'http' => array(
            'method' => 'PUT',
            'header' => "Content-Type: application/octet-stream\r\nContent-Length:{$chunkSize}\r\nContent-Range: bytes {$startRange}- {$endRange}/{$fileSize}",
            'content' => $contentBytes,
        )
    );
        
        

推荐阅读