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

后端 未结 2 1689
既然无缘
既然无缘 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 09:55

    Ok, so I made it work this way:

    Gemfile:

    gem 'fog'
    

    config/gce.yml:

    development:
      provider: Google
      google_storage_access_key_id: XXX
      google_storage_secret_access_key: XXX
    

    model:

      has_attached_file :avatar, 
                        :styles => { :big => "100x100#", :thumb => "25x25#" },
                        :storage => :fog,
                        :fog_credentials => "#{Rails.root}/config/gce.yml",
                        :fog_directory => "your bucket name",
                        :path => ":rails_root/public/users/:id/:style/:basename.:extension",
                        :url => "/users/:id/:style/:basename.:extension"
    

提交回复
热议问题