Introduction to Active Storage Part 3: Google Cloud Storage
And to complete the trifecta, here's how you can update the Active Storage code to use Google Cloud Storage:
1. Sign in to your Google Cloud Platform account and go to your console (the URL will be something like https://console.cloud.google.com/home/dashboard).
2. You need to create a new project, and then a storage bucket inside of the project. Record the names for both so you can add them to your storage_services.yml file.
3. You'll need to use GCS's API Manager to create credentials for your new bucket. Create a set of credentials that use the Google Cloud Datastore API. Download your credentials as JSON and store a copy of the file in your project at config/gcs.json.
NOTE: Obviously, you need to keep the keys in this file confidential. Don't check them into a public repository, for example. Manage it the same way you manage your database.yml or other files containing confidential information.
4. Update your storage_services.yml file with a configuration stanza for Google:
google: service: GCS project: gstroop-****** keyfile: bucket: ****-*******-9999
5. Add a line to your production.rb file:
config.active_storage.service = :google
6. Add the google-cloud-storage
gem to your Gemfile and run bundle install
.
7. Deploy the application. You should now be able to add user avatars and have then stored in the GCS bucket that you configured.