简体   繁体   English

使用PHP Slim API从Google Drive API下载文件

[英]Download file from Google Drive API with PHP Slim API

I have developed a PHP Slim API Webservice from where i access my Google Drive Files and return them to my Angular Frontend. 我已经开发了一个PHP Slim API Web服务,从这里可以访问我的Google Drive文件并将它们返回到Angular Frontend。 Now am not sure which is the best way to download my files from Google drive. 现在不确定哪种方法是从Google云端硬盘下载文件的最佳方法。 1. Can i directly download a file to my Browser from the GuzzleHTTP stream? 1.我可以从GuzzleHTTP流直接将文件下载到浏览器吗? 2. Or do i have to save the file to my server first before download? 2.还是在下载之前我必须先将文件保存到服务器上?

Please tell me which way is better and how i can accomplish that? 请告诉我哪种方法更好,我该如何做到呢?

My code so far: 到目前为止,我的代码:

$fileId = filter_var($data['id']);

$param = array(
             'alt' => 'media' ,
             'mimeType'=> $mimeType
             );

            $content = $client->files->get($fileId, $param);

    ***<here i want to process the file and download it to my browser>***

Then finally how can handle download in angular.js? 那么最后如何处理angular.js中的下载?

Inside a route, this should work: 在路线内,这应该起作用:

echo $content;
return $response->withHeader('Content-Description', 'File Transfer')
    ->withHeader('Content-Type', $mimeType)
    ->withHeader('Content-Disposition', 'attachment;filename="'.$yourFileName.'"')
    ->withHeader('Expires', '0')
    ->withHeader('Cache-Control', 'must-revalidate')
    ->withHeader('Pragma', 'public')
    ->withHeader('Content-Length', mb_strlen($content, '8bit') );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM