Set up image uploads to Google Cloud Storage

Do you want to use Google Storage for your image uploads? Here are the steps:

  • Set a default Google project if you don’t have one.

  • Get a developer key.

  • Create a bucket by going here. Enter a unique name and select a default storage class (I used multi-regional within the US).

Now we need to configure the Discourse instance. Go to settings, and add a filter for S3. Then make the changes below:

  • Check the “ enable s3 backups ” checkbox if you want to activate manual or automated backups

  • Enter the desired bucket name created above in “ s3 backup bucket ” if enable s3 backups is checked

  • Paste in both “ Access Key ID ” and “ Secret Access Key ” in their respective text fields (these were generated when the developer key was created)

  • In s3_endpoint , paste in the below endpoint:

    • https://storage.googleapis.com

That’s it! Try uploading an image - it should all work magically :slightly_smiling_face:


To ‘serve’ images directly from your domain, follow the steps below:

  • Make sure your bucket is accessible publicly. It needs to set up using object level permissions though

  • Set up a load balancer if you don’t already have one. For the backend, create a backend bucket, point it to the storage bucket created above, enable CDN, and connect it

  • For the URL map, create two rules. Hosts for both need to be *; paths need to be /original/* and /optimized/*; and the backend needs to point to the backend bucket - save the settings

  • In Discourse settings, change the s3 cdn url to your domain - make sure this ties in with how your load balancer rule has been set up

That’s it - the images should now come from www.yourdomain.com/


Backups are now possible, as @tuanpembual thankfully pointed out in this post . Essentially, you need to:

  1. Go to your project in Google Cloud Console
  2. Select Storage
  3. Select your bucket
  4. Go to the permissions tab
  5. Add new permission, fill your service account email with your account. for roles, select Storage Legacy Object Owner
  6. Save and done.
14 Likes