【问题标题】:Download file from Google Drive API with PHP Slim API使用 PHP Slim API 从 Google Drive API 下载文件
【发布时间】:2017-05-25 07:01:43
【问题描述】:

我开发了一个 PHP Slim API Web 服务,从中我可以访问我的 Google Drive 文件并将它们返回到我的 Angular 前端。现在不确定从 Google 驱动器下载我的文件的最佳方式。 1. 我可以直接从 GuzzleHTTP 流下载文件到我的浏览器吗? 2. 还是我必须先将文件保存到我的服务器才能下载?

请告诉我哪种方式更好,我该如何实现?

到目前为止我的代码:

$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>***

那么最后如何处理 angular.js 中的下载?

【问题讨论】:

    标签: php angularjs google-api slim


    【解决方案1】:

    在路线内,这应该可以工作:

    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') );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多