Skip to content

Instantly share code, notes, and snippets.

Created February 20, 2018 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/d5fff93d20fe15869625d1f3cfa3a23e to your computer and use it in GitHub Desktop.
Save anonymous/d5fff93d20fe15869625d1f3cfa3a23e to your computer and use it in GitHub Desktop.
App\Providers\GoogleDriveServiceProvider::class,
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
'google' => [
'driver' => 'google',
'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'),
'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'),
'folderId' => env('GOOGLE_DRIVE_FOLDER_ID'),
],
],
<?php
namespace App\Providers;
class GoogleDriveAdapter extends \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter
{
public function getService()
{
return $this->service;
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class GoogleDriveApiController extends Controller
{
public function getApi() {
$filename = 'namefile.txt';
$dir = '/';
$recursive = false;
$contents = collect(Storage::cloud()->listContents($dir, $recursive));
$file = $contents
->where('type', '=', 'file')
->where('filename', '=', pathinfo($filename, PATHINFO_FILENAME))
->where('extension', '=', pathinfo($filename, PATHINFO_EXTENSION))
->first();
$rawData = Storage::cloud()->get($file['path']);
return response($rawData, 200)
->header('ContentType', $file['mimetype'])
->header('Content-Disposition', "attachment; filename='$filename'");
}
}
$(window).on('load', function(){
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'),
'charset': 'utf-8'
},
type: 'GET',
url: 'getApi',
success: function(data) {
console.log(data);
},
error: function (data) {
console.log('Doh! : ', data);
}
});
});
Route::get('getApi', 'GoogleDriveApiController@getApi');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment