我想下载一个附件。我已收到附文,要求:
/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做这个吗?怎么做。
发布于 2019-11-03 16:24:38
我认为$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;https://stackoverflow.com/questions/58682015
复制相似问题