如何使用 Rails 和 Paperclip 在 Google Cloud Storage 上存储照片? [英] How to use Rails and Paperclip to store photos on Google Cloud Storage?
本文介绍了如何使用 Rails 和 Paperclip 在 Google Cloud Storage 上存储照片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
到目前为止,我一直在使用 Amazon S3 来存储用户的文件.
Until now, I have been using Amazon S3 for storing users' files.
这里需要做的就是:
- 为存储桶指定 Amazon S3 凭证
- 将
'aws-sdk'
gem 添加到 Gemfile - 在模型中:
- specify Amazon S3 credentials to the bucket
- add
'aws-sdk'
gem to the Gemfile - and in the model:
<小时>
has_attached_file :avatar,
:styles => { :big => "100x100#", :thumb => "25x25#" },
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":rails_root/public/users/:id/:style/:basename.:extension",
:url => "/users/:id/:style/:basename.:extension"
设置 Amazon S3 适配器.仅此而已.
To set the Amazon S3 adapter. That was all.
但是如何设置谷歌云引擎呢?到目前为止,我只找到了我可以使用的 fog gem .
But how to set up Google cloud engine? So far I found only the fog gem , which I could use.
但是,我应该如何配置模型以自动将所有上传的文件存储在 Google 服务器上?
However, how should I configure the model to automatically store all uploaded files on Google servers?
推荐答案
好的,所以我让它这样工作:
Ok, so I made it work this way:
宝石文件:
gem 'fog'
config/gce.yml:
development:
provider: Google
google_storage_access_key_id: XXX
google_storage_secret_access_key: XXX
型号:
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"
这篇关于如何使用 Rails 和 Paperclip 在 Google Cloud Storage 上存储照片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文