简体   繁体   中英

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. Now am not sure which is the best way to download my files from Google drive. 1. Can i directly download a file to my Browser from the GuzzleHTTP stream? 2. Or do i have to save the file to my server first before download?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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