Download the PHP package aslamhus/google-drive-uploader without Composer

On this page you can find all versions of the php package aslamhus/google-drive-uploader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package google-drive-uploader

Google Drive Uploader

Google Drive Uploader is a PHP class that simplifies uploading files to Google Drive using the Google Drive API. It supports basic and resumable uploads, allowing you to efficiently upload large files in chunks with options for asynchronous programming.

Google Drive API Documentation

This class relies on the Google API PHP client library and requires a Google service account with the Google Drive API enabled. Please refer to the following resources for additional information and setup instructions:

Setting up Google Drive API Service Account

To use the Google Drive Uploader, you need to set up a Google Cloud Console service account and obtain the necessary credentials. Follow these steps:

  1. Create a Google Cloud project: Google Cloud Console
  2. Enable the Google Drive API: Google Workspace Product Library
  3. Set up OAuth for your app: Navigate to APIs and services > OAuth consent screen.
  4. Choose scopes: Select the required scopes for Google Drive API. See available scopes here.
  5. Create access credentials (API key): Navigate to APIs & Services > Credentials, then click "Create Credentials" > "API key."
  6. Create access credentials (OAuth client ID): Navigate to APIs & Services > Credentials, then click "Create Credentials" > "OAuth client ID." Add authorized URLs and download the client secret JSON file.
  7. Download the service account secret: Navigate to Service accounts > Keys > Create key.

  8. Create a service account: Navigate to IAM & Admin > Service Accounts, then click "Create Service Account."
  9. Add the service account to the Google Drive folder by granting permissions to the service account email.

You're now ready to use the Google Drive Uploader!

Usage

Install

Config

Before you begin uploading you must set your GOOGLE_APPLICATION_CREDENTIALS environment variable and create a drive folder with shared permissions granted to your service account email. Make sure you've followed the steps above if you haven't already got a service account in Google Cloud Console.

  1. Service account credentials

GoogleDriveUploader sets default credentials via environment variables like so:

  1. Drive folder id

In order to upload a file to a Google Drive account, create a folder in your desired google drive account where you'd like your uploads to be delivered. Then grant your service account email address access to the folder. You can find your service account email in Google Cloud Console.

Once you've done this, simply copy the drive folder id from the drive folder url. You can find the drive folder url by navigating to the appropriate folder in Google Drive and then copying the id string from url:

https://drive.google.com/drive/folders/file-id-string

Basic Upload

Use this method for small files.

Resumable Upload

Use this method for large uploads and/or when the upload process has a high chance of being interrupted.

Asynchronous Resumable Upload

To perform an aysnchronous upload, use the resumable upload method.

Resume an Interrupted Upload

Callbacks

onChunkRead

You can pass an optional onChunkRead callback method to startResumable and resume.

Memory Limits

The basicUpload method loads the file into memory using file_get_contents, so it's best not to use large files with this method. If you do, you may run into memory limit errors.

The resumable upload is performed by splitting the file into chunks which are by default 262144 bytes. This is the Google recommended chunk size. You should be able to upload very large files without encountering any memory limits.

Exception Handling

The class includes a custom exception class, GoogleDriveUploaderException, to handle errors in the Google Drive uploading process.

Testing

Before testing, make sure you've installed dev dependencies, and set up your .env file with the GOOGLE_APPLICATION_CREDENTIALS and GOOGLE_DRIVE_FOLDER_ID.

Note: running the tests will upload 3 small test videos to your good drive folder with the id you specify

Then run:

Feel free to contribute or report issues on GitHub.

Happy uploading!


All versions of google-drive-uploader with dependencies

PHP Build Version
Package Version
Requires google/apiclient Version ^2.15
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package aslamhus/google-drive-uploader contains the following files

Loading the files please wait ....