如何使用Rails和Paperclip在Google Cloud Storage上存储照片? [英] How to use Rails and Paperclip to store photos on Google Cloud Storage?

查看:80
本文介绍了如何使用Rails和Paperclip在Google Cloud Storage上存储照片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到现在,我一直在使用Amazon S3来存储用户的文件.

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

这里需要做的所有事情是:

All what has been needed to do here was:

  1. 在存储桶中指定Amazon S3凭据
  2. 'aws-sdk' gem添加到Gemfile
  3. 并在模型中:
  1. specify Amazon S3 credentials to the bucket
  2. add 'aws-sdk' gem to the Gemfile
  3. 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.

但是如何设置Google云引擎?到目前为止,我只发现可以使用的雾宝石.

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?

推荐答案

好,所以我这样工作:

宝石文件:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆