You are here
Home > Php > Connect Google App Engine with Google Cloud Storage

Connect Google App Engine with Google Cloud Storage

Hello Friends, I hope you are doing well. Today we are going to see how to connect Google App Engine with Google Cloud Storage. App Engine is a fully managed, serverless platform for developing and hosting web applications at scale while Cloud Storage is a RESTful file storage service for storing and accessing data on Google Cloud Platform. Google Cloud Storage service can be used to serve website content, store data for archival and disaster recovery or distributing large files to users via direct download. Here we are going to develop a one page app which will give us options to upload file, list files as well as delete files. So, without wasting any time let’s do it by following below steps:-

Step 1: Login to Google Cloud Console and Create a Project



Step 2: Go to App Engine and Create Application using below command in Cloud Shell or you can also follow steps by clicking on create application see screenshots below for your reference


app-engine-with-cloudstorage-create-application-step-1 app-engine-with-cloudstorage-create-application-step-3 app-engine-with-cloudstorage-create-application-step-4
Step 1 Step 2 Step 3 Step 4

Step 3: After receiving success open Cloud Shell if not already opened and click on pencil icon to Launch Editor


Step 4: Download Google Cloud Storage Library using below command

Composer comes pre-installed on Cloud Shell so you need to install it, but still if you need guidance to install composer you check here
After executing above command you’ll see vendor directory which contains cloud storage library and two more files called composer.json and composer.lock

Step 5: Now It’s Time to Code


We configure our App Engine app’s settings in the app.yaml file. The app.yaml file also contains information about your app’s code, PHP runtime, and entrypoint.

Here we are defining an environment variable named as BUCKET_NAME which we will use in our code, this bucket name you can get from Navigation Menu => Storage Option in GCP Console. Actually, when we create App Engine project a bucket is automatically created by App Engine for the use in your app with named as “”.


All necessary functions for uploading, listing and deleting files are defined here in this file


User requests routing code which responds according to path i.e opening home page sending ajax request to requests.php showing 404 on invalid path


Code to list objects of given bucket, uploading and deleting objects (files)


This file is called through ajax to upload file on google cloud storage and here you can see $cloudPath variable which is used to store file path and if we need to store it in database we can do so and later we can fetch it from our database instead of cloud storage api. We can also use Cloud SQL in our application to make our application fully cloud based if you are not aware how to use Cloud SQL with App Engine then checkout this post Connect Google App Engine with Google Cloud SQL.

Step 6: Go to Editor which we had launched in step 3 and upload all the files created in step 5.

app-engine-with-cloud-storage-upload-files app-engine-with-cloud-storage-files-uploaded

Step 7: Deploy App using below command


Step 8: Access App



Note: –

We don’t have to create service account and download private key just as we had done in Upload File to Google Cloud Storage using PHP article as this code is running on App Engine and App Engine app by default connected to a service account which have access to Cloud Storage.


NetBeans Project Download



Thank you Friends
Please don’t forget share if you it useful

Rajesh Kumar Sahanee
I am a passionate Java Developer and I like Computer Programming. I love to do some interesting experiments and listening music in my free time.