Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP Laravel从Outlook API下载附件?_Php_Laravel_Microsoft Graph Api - Fatal编程技术网

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

如何使用PHP Laravel从Outlook API下载附件?,php,laravel,microsoft-graph-api,Php,Laravel,Microsoft Graph Api,我想下载一个附件。我已与附件达成请求: /me/message/{message\u id}/attachments/{attachment\u id} 答复是: [_propDict:protected] => Array ( [@odata.context] => https://graph.microsoft.com/v1.0/$metadata#users('username')/messages('messageId')/attach

我想下载一个附件。我已与附件达成请求:

/me/message/{message\u id}/attachments/{attachment\u 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
。我可以用
contentbYes
和如何做到这一点。

我认为
$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;

它给了我一根绳子,那根绳子里是什么?这就是您要查找的附件内容吗?它是字节格式。但我使用base64_decode()进行转换,可以读取有关该文件的一些文本。转换文本中的xls或png示例。但我无法下载为文件。更新了我的答案,以显示如何使用我在答案中发布的代码下载为文件。请确保在内容类型标头中指定正确的MIME类型。然后你可以下载任何文件。