How to use Rails and Paperclip to store photos on Google Cloud Storage?

后端 未结 2 1687
既然无缘
既然无缘 2021-02-01 09:25

Until now, I have been using Amazon S3 for storing users\' files.

All what has been needed to do here was:

  1. specify Amazon S3 credentials to the bucket
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 10:02

    For Rails > 5.2, Active Storage is available. The docs are a great place to start with.

    In config/environments/production.rb :

    # Store files on Google cloud storage.
    config.active_storage.service = :google
    

    In config/storage.yml :

    google:
      service: GCS
      credentials: <%= Rails.root.join("path/to/keyfile.json") %>
      project: ""
      bucket: ""
    

    In your User Model :

    class User < ApplicationRecord
      has_one_attached :avatar
    end
    

提交回复
热议问题