John Davidson

php - Laravel download file from google drive

0 comments
Message:


I want to download some mixed files from google drive using my Laravel App but for exp Images download correctly, but Docs file comes empty


Provider:


\Storage::extend("googleConsole", function($app, $config) {
$client = new \Google_Client;
$client->setClientId($config['clientId']);
$client->setClientSecret($config['clientSecret']);
$client->refreshToken($config['refreshToken']);

$service = new \Google_Service_Drive($client);
$adapter = new GoogleDriveAdapter($service, $config['folderId']);
return new Filesystem($adapter);
});

Controller:


$response = Storage::disk('googleConsole')->download($fileName);
$file = $response->send();


My Answer:
new class {
public function url($path)
{
$fileId = 'YOUR_GOOGLE_DRIVE_FILE_ID';
$accessToken = 'YOUR_ACCESS_TOKEN';

$url = "https://www.googleapis.com/drive/v3/files/{$fileId}?alt=media";
$headers = [
'Authorization' => 'Bearer ' . $accessToken,
];

return $url;
}
};

// Usage
$url = Storage::url('path/to/file.docx');
return response()->download($url);

Rate this post

5 of 5 based on 3774 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us