How to set up Pimcore to use Google Cloud Storage service

What you'll learn with this guide

This guide will show you how to set up Pimcore to use the Google Cloud Storage service. Google Cloud Storage SDK and stream wrapper will be used. The guide is based on Pimcore documentation for Amazon AWS Storage Setup.

Where to use

Assume you want to upload files to your Pimcore application, but for some reason, be it that other applications or services need to access those same files via Google Cloud Storage or you just want to have a backup of your files saved on the cloud, you want the process of uploading files to Google Cloud Storage to be automated. You only want to upload a file to Pimcore and let it handle uploading the same file to Google Cloud Storage by itself. To achieve this, a bit of coding is needed which will be shown in this guide.

Solution

In this guide, it is assumed that you are familiar with Google Cloud Storage, you have a bucket on the cloud and you downloaded a JSON file containing mainly your private key, but other useful data as well.
The solution consists of the following steps:

  1. Install Google Cloud Storage Client Library
  2. Create a custom startup.php
  3. Configure the Event Listeners
  4. Add a class to respond to the events
  5. Customize the storage locations of Pimcore
  6. Migrate the existing content

1. Install Google Cloud Storage Client Library

Run the following command in your Pimcore document root:

2. Create a custom startup.php

Create a new file (or re-use existing) with the following code in /app/startup.php:

3. Configure the Event Listeners

Create a new file (or re-use existing) with the following code in /app/config/services.yml:

4. Add a class to respond to the events

Create a new file named /GoogleCloudStorageListener.php with the following code in your bundle source: /src/CommonBundle/EventListener/GoogleCloudStorageListener.php

Create a new file named /GoogleCloudStorageListener.php with the following code in your bundle source: /src/CommonBundle/EventListener/GoogleCloudStorageListener.php

5. Customize the Storage Locations of Pimcore

Create a new file named /constants.php in /app/constants.php and put the following code in it:

6. Migrate Existing Content

Migrating existing content from Pimcore application directories to Google Cloud Storage is done by using gsutil tool. Run the following command from your Pimcore root directory to copy the contents of Pimcore application’s assets directory to your bucket on Google Cloud Storage.

Here's the official documentation for gsutil installation and gsutil rsync usage. You'll most certainly find it useful!

Does it work?

Visit your Pimcore administration and try to upload a file, the file should be uploaded and visible in Pimcore administration as well as Google Cloud Storage.

Deleting a file in Pimcore administration results in deletion of the file on the cloud. Vice versa does not apply

Do you have more questions, or having issues while implementing this? Reach out to us; we’ll be glad to help! 

Looking for Exponential Growth? Let’s Get Started.
Explore next

Pimcore Tutorial

Check out our step-by-step tutorials on how to use Pimcore features and solutions.

Discover more