Quick StartNodeJS ServerGoogle Cloud Storage Integration

Prerequisites

  1. A Google Cloud Platform account
  2. A project on Google Cloud Platform (These 2 steps are covered in the Mobile App - Google Maps Integration)
  3. Install GCloud and run auth command
gcloud auth application-default login --project=YOUR_PROJECT_ID

Create a bucket

  1. Go to Google Cloud Platform on https://console.cloud.google.com/
  2. Click on console.
  3. Select the project you want to use.
  4. In the searchbar, search for “Buckets” and click on “Buckets”.

Buckets
  1. Click on “Create Bucket”.

Create bucket
  1. Add a new name and other required data for your bucket and click on “Create”. (Make sure you select a region that is close to your server’s location)

Bucket name
  1. You should see a screen similar to this one

Bucket created
  1. Go to the PERMISSIONS tab and allow anyone to view the files from the bucket
  • Click on GRANT ACCESS
  • Add allUsers as new principal
  • Add Storage Object Viewer as role

Permissions

allUsers

grant role

The bucket is now created and anyone can see the images uploaded there. Let’s see how we can upload and delete files from the bucket.

Create a service account

  1. In the Google Console platform, search for Service Accounts IAM

Service accounts
  1. Click on the “Create Service Account” button
  2. Add a name and description for your service account and click on “Continue”

Service accounts
  1. Grant the service account the Storage Admin role and click on “Done”

Service account permission
  1. Click on the service account you just created, got to the Keys tab and click on Add key with JSON format. This will download a JSON file with the credentials for your service account.

Service account key
  1. Copy the content of the JSON file that was downloaded
  2. Create a service-account.json file in the root of the server and paste the content of the JSON file inside it

Service account key in server

Add bucket to .env

Add name of the bucket inside the .env file in the root of the server

GCLOUD_STORAGE_BUCKET=YOUR_BUCKET_NAME