Chúc mừng Tết Trung Thu 15% off everything Shop the sale
Google Drive Attachments guides

Set up Google Drive Attachments: connect Google and move your files

Connect your forum to Google Drive, choose direct or cache mode, and move existing attachments across safely.

Updated 4 min read By the D.C Style team

On this page

Before you start

Google Drive Attachments stores your forum's files in Google Drive instead of on your server's disk, which keeps hosting costs down as your attachments grow. Setting it up has three parts: create an OAuth client in Google Cloud, connect your forum to it, then decide how files are stored and whether to move the ones you already have. Most of the time goes into the Google Cloud part.

Check your PHP version first

The add-on bundles Google's own API libraries, and those need PHP 8.1 or newer, even though XenForo 2.2 itself runs on older versions. The libraries check the PHP version on every page load, so on PHP 8.0 or older every page of your forum stops with an error that mentions "Composer detected issues in your platform". Check your version before installing: find your XenForo, PHP and MySQL versions. If it has already happened, this guide gets you back in.

Create a Google OAuth client

  1. Open the Google Cloud Console and create a project, or select an existing one.
  2. Enable the Google Drive API for the project.
  3. Create OAuth 2.0 credentials of the Web application type. If Google asks you to set up the consent screen first, do that and come back.
  4. Under Authorized redirect URIs, add your forum's callback address:
    https://yourforum.com/admin.php?dc-gda/callback
  5. Copy the Client ID and Client Secret Google shows you.

Tip: Google compares the redirect URI character for character, and the add-on builds it from your Board URL (Setup > Options > Basic options). A redirect_uri_mismatch error means the two differ: check https, www and any folder your forum lives in.

Connect your forum to Google Drive

  1. Go to Setup > Options > D.C Style - Google Drive Attachments and fill in Google OAuth Client ID and Google OAuth Client Secret.
  2. Optionally, create a folder in Drive and enter its ID in Google Drive Folder ID. The ID is the last part of the folder's URL. Leave it empty to use the root of the Drive.
  3. In the Admin CP menu, open D.C Style - Google Drive Attachments > Authorize with Google, click Authorize with Google and allow access with the Google account that owns the Drive.
  4. Back on that page you should see "Connected to Google Drive as" your account, and Token auto-refresh should say Active. Click Test connection to confirm the folder is reachable.
  5. Turn on Enable Google Drive storage in the options. New uploads now go to Drive. Files you already have stay where they are until you migrate them.

If Token auto-refresh says Missing, click Disconnect and authorize again. Without a refresh token the connection stops working when the current token expires.

Direct mode or local cache mode

By default the add-on works in direct mode: XenForo reads and writes its data and internal_data files on Google Drive. That covers more than attachments. Avatars and files other add-ons keep there are stored on Drive too, so each of them loads from Google.

Turn on Enable local temporary cache for the other mode. New files are written to your server first, so uploads stay fast. A scheduled task then syncs attachments to Drive every three hours and deletes the local copies once they are safely uploaded. This relies on XenForo's scheduled tasks running, so read keep scheduled tasks running if your forum is quiet at night.

File extensions to sync to Google Drive limits syncing to the types you list, one per line (for example zip or pdf). Anything else stays on your server. Leave it empty to sync every attachment.

Move the files you already have

On the Authorize with Google page, Migration tools has Migrate attachments to Google Drive. It runs as a background job and skips files that are already there, so it is safe to run again. On a large forum, the command line is faster and has no browser time limit:

php cmd.php xf-rebuild:dcGda-migrateToGoogleDrive

Useful options: --concurrency (uploads at once, 10 by default), --batch, --start-id and --end-id to split the work, and --delete-local to remove each local copy after it uploads. --cleanup-local removes local copies of files that were already migrated. Take a backup before deleting anything. Running XenForo commands over SSH explains the basics.

Before you uninstall

Warning: Uninstalling does not bring your files back from Google Drive. Run Migrate attachments to local storage first (or php cmd.php xf-rebuild:dcGda-migrateToLocal), wait for it to finish, and only then uninstall. What uninstalling removes.

Everything else about the add-on, including its version history, is on the Google Drive Attachments page.

Still stuck? Open a support ticket with your XenForo and PHP versions, what the Authorize with Google page shows, and any error from Logs > Server error log.

Did this guide help? Thanks! Glad it worked. Sorry about that. What went wrong? Thanks for telling us. We'll use it to improve this guide.

What went wrong?
Need a reply? Open a Google Drive Attachments ticket instead.

Google Drive Attachments

v1.2.0 · $25.00

Product page → Ask about Google Drive Attachments →