Git Product home page Git Product logo

lara10-gdrive's Introduction

laravel-google-drive-storage

gdrive This package allow to store and get data from google drive like S3 AWS in laravel

Support

  • php 8.1
  • laravel 9

Installation

You can install the package via composer:

composer require yaza/laravel-google-drive-storage

copy to .env

FILESYSTEM_CLOUD=google
GOOGLE_DRIVE_CLIENT_ID=xxx.apps.googleusercontent.com
GOOGLE_DRIVE_CLIENT_SECRET=xxx
GOOGLE_DRIVE_REFRESH_TOKEN=xxx
GOOGLE_DRIVE_FOLDER=

example

FILESYSTEM_CLOUD=google
GOOGLE_DRIVE_CLIENT_ID=xxx.apps.googleusercontent.com
GOOGLE_DRIVE_CLIENT_SECRET=xxx
GOOGLE_DRIVE_REFRESH_TOKEN=xxx
GOOGLE_DRIVE_FOLDER=backups

Setup Google Keys

Usage

you can use storage driver function by laravel
example :

 Storage::disk('google')->put($filename, File::get($filepath));

refrensi code opration sample code


or use helper from this package
  • Put File
use Yaza\LaravelGoogleDriveStorage\Gdrive;

Gdrive::put('location/filename.png', $request->file('file'));
// or
Gdrive::put('filename.png', public_path('path/filename.png'));
  • Get File
use Yaza\LaravelGoogleDriveStorage\Gdrive;

$data = Gdrive::get('path/filename.png');

return response($data->file, 200)
    ->header('Content-Type', $data->ext);
  • Get Large File with stream
use Yaza\LaravelGoogleDriveStorage\Gdrive;

  $readStream = Gdrive::readStream('path/filename.png');

return response()->stream(function () use ($readStream) {
    fpassthru($readStream->file);
}, 200, [
    'Content-Type' => $readStream->ext,
    //'Content-disposition' => 'attachment; filename="'.$filename.'"', // force download?
]);
  • download file
use Yaza\LaravelGoogleDriveStorage\Gdrive;

 $data = Gdrive::get('path/filename.png');
        return response($data->file, 200)
            ->header('Content-Type', $data->ext)
            ->header('Content-disposition', 'attachment; filename="'.$data->filename.'"');
  • delete
use Yaza\LaravelGoogleDriveStorage\Gdrive;

 Gdrive::delete('path/filename.png');
  • delete directory
use Yaza\LaravelGoogleDriveStorage\Gdrive;

  Gdrive::deleteDir('foldername');
  • make directory
use Yaza\LaravelGoogleDriveStorage\Gdrive;

  Gdrive::makeDir('foldername');
  • rename directory
use Yaza\LaravelGoogleDriveStorage\Gdrive;

  Gdrive::renameDir('oldfolderpath', 'newfolder');
  • all folder & file
use Yaza\LaravelGoogleDriveStorage\Gdrive;

Gdrive::all('/');
// or
Gdrive::all('foldername');

output

Illuminate\Support\Collection {#804 ▼ // app/Http/Controllers/UploadController.php:70
  #items: array:3 [▼
    0 => League\Flysystem\DirectoryAttributes {#798 ▶}
    1 => League\Flysystem\FileAttributes {#796 ▶}
    2 => League\Flysystem\DirectoryAttributes {#783 ▶}
  ]
  #escapeWhenCastingToString: false
}
  • all folder & file with sub folder
use Yaza\LaravelGoogleDriveStorage\Gdrive;

Gdrive::all('/', true);
// or
Gdrive::all('foldername', true);

output

Illuminate\Support\Collection {#804 ▼ // app/Http/Controllers/UploadController.php:70
  #items: array:3 [▼
    0 => League\Flysystem\DirectoryAttributes {#798 ▶}
    1 => League\Flysystem\FileAttributes {#796 ▶}
    2 => League\Flysystem\DirectoryAttributes {#783 ▶}
  ]
  #escapeWhenCastingToString: false
}

Limitations

Using display paths as identifiers for folders and files requires them to be unique. Unfortunately Google Drive allows users to create files and folders with same (displayed) names. In such cases when unique path cannot be determined this adapter chooses the oldest (first) instance. In case the newer duplicate is a folder and user puts a unique file or folder inside the adapter will be able to reach it properly (because full path is unique).

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

Thanks to Masbug

License

The MIT License (MIT). Please see License File for more information.

lara10-gdrive's People

Contributors

yaza-putu avatar dependabot[bot] avatar github-actions[bot] avatar matthelosh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.