gpt4 book ai didi

php - 如何使用 PHP Laravel 从 Outlook API 下载附件?

转载 作者:行者123 更新时间:2023-12-01 13:13:10 26 4
gpt4 key购买 nike

我要下载附件。我已收到请求的附件:

/me/message/{message_id}/attachments/{attachment_id}

响应是:

[_propDict:protected] => Array
(
[@odata.context] => https://graph.microsoft.com/v1.0/$metadata#users('username')/messages('messageId')/attachments/$entity
[@odata.type] => #microsoft.graph.fileAttachment
[@odata.mediaContentType] => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
[id] => xxx
[lastModifiedDateTime] => 2019-11-02T17:50:52Z
[name] => xxx.xlsx
[contentType] => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
[size] => 33459
[isInline] =>
[contentId] => f_k2hv435z0
[contentLocation] =>
[contentBytes] => GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #374
[size:GuzzleHttp\Psr7\Stream:private] =>
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
)
)

没有sourceUrl,只有contentBytes。我可以使用 contentBtyes 来实现吗?如何实现。

最佳答案

我认为 $object->getContentBytes() 应该适合你。

UPD:如果你想将内容下载为文件,你可以做类似的事情:

$fileName = "download.txt";
$contents = $object->getContentBytes(); // base64_decode() here if needed

header("Content-type: text/plain"); // Or any other format
header("Content-Disposition: attachment; filename=" . $fileName);
print $contents;
die;

关于php - 如何使用 PHP Laravel 从 Outlook API 下载附件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58682015/

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