当前位置: 首页 > 软件库 > 大数据 > 数据存储 >

laravel-google-drive-demo

授权协议 Readme
开发语言 C#
所属分类 大数据、 数据存储
软件类型 开源软件
地区 不详
投 递 者 万承志
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Laravel & Google Drive Storage

ko-fi

Demo project with Laravel 5.4

Look at the commit history to see each of the steps I have taken to set this up.

Set up this demo project locally

git clone git@github.com:ivanvermeyen/laravel-google-drive-demo.git
composer install

I took care of this:

This will also install only one additional package that is not included by Laravel out of the box:

"nao-pon/flysystem-google-drive": "~1.1"

I have included GoogleDriveAdapter and GoogleDriveServiceProvider which I have added to the providers array in config/app.php, and added a google disk in config/filesystems.php:

'disks' => [

    // ...

    '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'),
        // 'teamDriveId' => env('GOOGLE_DRIVE_TEAM_DRIVE_ID'),
    ],

    // ...

],

Create your Google Drive API keys

Detailed information on how to obtain your API ID, secret and refresh token:

Update .env file

Add the keys you created to your .env file and set google as your default cloud storage. You can copy the .env.example file and fill in the blanks.

FILESYSTEM_CLOUD=google
GOOGLE_DRIVE_CLIENT_ID=xxx.apps.googleusercontent.com
GOOGLE_DRIVE_CLIENT_SECRET=xxx
GOOGLE_DRIVE_REFRESH_TOKEN=xxx
GOOGLE_DRIVE_FOLDER_ID=null
#GOOGLE_DRIVE_TEAM_DRIVE_ID=xxx

Using multiple Google Drive accounts

If you want to use multiple Google Drive accounts in a single Laravel app, you need to get the API keys for each one as described above and store them separately in your .env file:

MAIN_GOOGLE_DRIVE_CLIENT_ID=xxx.apps.googleusercontent.com
MAIN_GOOGLE_DRIVE_CLIENT_SECRET=xxx
MAIN_GOOGLE_DRIVE_REFRESH_TOKEN=xxx
MAIN_GOOGLE_DRIVE_FOLDER_ID=null

BACKUP_GOOGLE_DRIVE_CLIENT_ID=xxx.apps.googleusercontent.com
BACKUP_GOOGLE_DRIVE_CLIENT_SECRET=xxx
BACKUP_GOOGLE_DRIVE_REFRESH_TOKEN=xxx
BACKUP_GOOGLE_DRIVE_FOLDER_ID=null

Then you should add a disk in config/filesystems.php for each account using the google driver and the account specific keys:

'main_google' => [
    'driver' => 'google',
    'clientId' => env('MAIN_GOOGLE_DRIVE_CLIENT_ID'),
    'clientSecret' => env('MAIN_GOOGLE_DRIVE_CLIENT_SECRET'),
    'refreshToken' => env('MAIN_GOOGLE_DRIVE_REFRESH_TOKEN'),
    'folderId' => env('MAIN_GOOGLE_DRIVE_FOLDER_ID'),
],

'backup_google' => [
    'driver' => 'google',
    'clientId' => env('BACKUP_GOOGLE_DRIVE_CLIENT_ID'),
    'clientSecret' => env('BACKUP_GOOGLE_DRIVE_CLIENT_SECRET'),
    'refreshToken' => env('BACKUP_GOOGLE_DRIVE_REFRESH_TOKEN'),
    'folderId' => env('BACKUP_GOOGLE_DRIVE_FOLDER_ID'),
],

Now you can access the drives like so:

$mainDisk = Storage::disk('main_google');
$backupDisk = Storage::disk('backup_google');

Keep in mind that there can only be one default cloud storage drive, defined by FILESYSTEM_CLOUD in your .env (or config) file. If you set it to main_google, that will be the cloud drive:

Storage::cloud(); // refers to Storage::disk('main_google')

Available routes

Route Description
/put Puts a new test.txt file to Google Drive
/put-existing Puts an existing file to Google Drive
/list Lists all files in Google Drive (root directory, not recursive by default)
/list-folder-contents List all files in a specific folder
/get Finds and downloads the test.txt file from Google Drive
/create-dir Creates a Test Dir directory
/create-sub-dir Creates a Test Dir directory and a Sub Dir sub directory
/put-in-dir Puts a new test.txt file to the Test Dir sub directory
/newest Puts a new file to Google Drive and then fetches it
/delete Delete a file from Google Drive
/delete-dir Delete an entire directory from Google Drive
/rename-dir Rename a directory in Google Drive
/put-get-stream Use a stream to store and get larger files
/share Change permissions to share a file with the public
/export/{basename} Export a Google doc (to PDF)

This is a very basic example to get you started. To see the logic behind these routes, check routes/web.php.

Interesting Reads

  • 近段时间需要使用google colab训练一些神经网络,但是colab默认是不能读入google drive的数据的,每次都要重新上传,费时费力。所以这篇博客是让colab用户能够使用google drive的工作文件夹 2018年12月亲测有效。 step1 首先需要让colab获得google drive的授权,在google colab里执行如下代码: !apt-get install -

  • 一、新建新的jupyternotebook,在空白的单元格中输入 !apt-get install -y -qq software-properties-common python-software-properties module-init-tools !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null !apt-

  • wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.goog

  • 方法一:用IDM下载 https://zhuanlan.zhihu.com/p/143950267 方法二:将文件下载到Linux服务器,再从服务器下载到本地 https://gwliang.com/2020/05/26/linux-control-download-onedrive-files/ 方法三:MultCloud云盘管理工具

  • 使用colab训练深度学习模型的时候,需要读入本地采集好的数据集。这时候可以将数据集先上传到google drive云端硬盘,再在colab的notebook读取google drive的数据集(文本、图片、数据表等)。colab类似一台linux服务器,要使用google drive就需要把drive挂在到主机上。 这时候需要以下三个步骤: 1.首先需要让colab获得google drive的

  • pip install gdown import gdown output = "data.tar" id = "1srnBQUOho1R8EW8s50A1VKdecnqoOeXZwer" gdown.download(id=id, output=output, quiet=False)  

  •        近期在做深度学习相关模型训练时,由于本地电脑不够强大,所以选择了可以每天免费使用12小时的google colab环境,为了保持模型文件和训练数据文件,需要将其与google driver配合使用。然而在使用的过程中发现对于较大的数据(如训练数据集、训练的模型数据等),通常会存在google colab虚拟机中网盘文件与真实的google网盘文件不同步的情况。这样在退出虚拟机时会导致

  • 通过chrome下载如果中断了, 有可能需要重新下载。如果是几个G的文件,重新下载成本很高,使用下面方法下载会稳定一些。 下载google drive的文件 import requests def download_file_from_google_drive(id, destination): def get_confirm_token(response): for k

  • 转自:http://www.cnblogs.com/mahun/p/4168633.html 作者:梦中的天堂 一、Google Drive Google Drive 里并不提供创建直接下载链接的选项,但是可以通过小小的更改链接形式就能把分享的内容保存到本地。例如,一份通过 Google Drive 分享的文件链接形式为: https://drive.google.com/file/d/FILE_

  • wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.goog

  • 一般在colab中训练好模型之后,我们都希望保留模型参数或者实验结果,这样下次就可以直接访问而不需要再次run model。 首先保存模型的代码比较简单,比如用pytorch的话: import torch torch.save(model, './model.pt') 或者用pickle保存模型结果,具体怎么使用pickle可以看我的另一篇文章。 但问题是,这个保存并没有和自己的google

  • 如何使用worker的方法直接略过,网上有很多教程, 但是把长长的worker如何设置为自己的域名却很少,故分享记录。 How to Setup Cloudflare Workers on a Custom Domain

 相关资料
  • Google drive upload Google drive upload is a collection of shell scripts runnable on all POSIX compatible shells ( sh / ksh / dash / bash / zsh / etc ). It utilizes google drive api v3 and google OAut

  • Google Drive SDK 是 Google Drive 服务的接口开发包。Google Drive 是 Google 提供的云存储服务。 此 API 提供多种编程语言版本,涉及 .NET/Java/Objective-C/Go/PHP/Python/Ruby/JavaScript 语言。

  • 我试图运行此Java代码,以便列出我的Google Drive中的所有文件: 当我运行代码时,我被重定向到登录页面以输入我的Google的电子邮件凭据。如何跳过此步骤?代码我将完全在后台使用,我需要使用JSON文件中的凭据。

  • 我的桌面应用程序,写在Java,试图下载公共文件从谷歌驱动器。正如我所发现的,它可以通过使用文件的来实现(这是为了能够在没有用户授权的情况下下载公共文件)。 因此,下面的代码可以处理小文件: 但它对大文件不起作用,因为在这种情况下,未经用户确认并带有google病毒扫描警告,文件不能直接通过下载。请参阅示例:web内容链接。 所以我的问题是如何在没有用户授权的情况下从Google Drive获取公

  • 我的代码有问题。你们能帮帮我吗? 进程 出现错误(Type=内部服务器错误,状态=500)。GoogleJSONClient.(LCOM/Google/API/Client/HTTP/HTTPTransport;LCOM/Google/API/Client/HTTP/HTTPRequestInitializer;LJava/Lang/String;LJava/Lang/String;LCOM/Go