flutter - 如何在 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>
}
谁能帮忙分享我们如何将二进制数据传递给请求?
解决方案
您可以尝试以下代码:
$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,
)
);
推荐阅读
- c++ - 当给定 const char * 作为模板化参数的类型时,为什么编译器会选择 bool 而不是 string_view?
- typescript - 打字稿包中的意外令牌导出
- python - 如何订购 DictWriter 的标题(不按字母顺序)?
- javascript - 出现视频时暂停滑块
- python - 如何忽略矩阵乘法中的零?
- python-3.x - 使用字符串列表执行带参数的函数
- constraints - 在 Azure 数据工作室中,我找不到添加外键或任何其他约束选项
- android - SQLLITE 将列及其数据从 TableA 移动到 TableB
- sql - 除以零也使用 *-1
- python - 查找列表中项目结尾的重复项