2

我正在创建一个rails插件rails new plugin my_plugin --mountable

这是相当多的工作要弄清楚,但它应该使用carrierwave将文件上传到S3,但它说好的但没有上传任何东西

Carrierwave 用于生成上传器,rails g uploader photo 文件如下所示

# my_engine/app/uploaders/my_engine/photo_uploader.rb

# encoding: utf-8
module my_engine
 class PhotoUploader < CarrierWave::Uploader::Base
  # Choose what kind of storage to use for this uploader:
  storage :file
  # storage :fog

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
 end
end

该模型有一个坐骑:照片,PhotoUploader

module PdfGeneratorEngine
  class Assemble < ActiveRecord::Base
    attr_accessible :color, :photo, :qr_code_url, :text

    mount_uploader :photo, PhotoUploader
  end
end

我的 CarrierWave 配置文件是这个

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',
    :aws_access_key_id      => 'MY_ACCES_KEY',
    :aws_secret_access_key  => 'MY_SECRET_KEY',
    :provider => 'AWS',
    :region => 'eu-west-1'
  }
  config.fog_directory  =  'my.bucket.com'
  config.fog_host       =  'https://s3-eu-west-1.amazonaws.com/my.bucket.com'
  config.storage = :fog
  config.s3_use_ssl = true
  config.fog_public = true
end

所以首先它开始对fog_host尖叫,如果它是asset_host就可以了

接下来它的问题在于 s3_use_ssl,而它是 CarrierWave 的 github 上的一个合并问题。但是主机已经被定义为 https:// 所以我不明白为什么该行是必要的。

之后它说“好的,它完成了”,当我尝试(使用守护程序)检查文件时,那里什么都没有。

我错过了什么?还是 CarrierWave 和 Rails 可安装引擎存在问题?

4

2 回答 2

1

在你的 photo_uploader.rb

评论存储:文件和取消评论存储:雾

  # storage :file
  storage :fog   

-- 看看你的fog.rb,它和这里给出的不一致

载波#using-amazon-s3

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',                        # required
    :aws_access_key_id      => 'xxx',                        # required
    :aws_secret_access_key  => 'yyy',                        # required
    :region                 => 'eu-west-1'                   # optional, defaults to 'us-east-1'
    :hosts                  => 's3.example.com'              # optional, defaults to nil
    :endpoint               => 'https://s3.example.com:8080' # optional, defaults to nil
  }
  config.fog_directory  = 'name_of_directory'                     # required
  config.fog_public     = false                                   # optional, defaults to true
  config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  # optional, defaults to {}
end
于 2012-12-19T10:05:52.223 回答
0

好的 所以 CarrierWave 有点问题。

我已经快速设置了 RightAws,现在它上传到 S3,我可以从我的守护进程中找到它。

在我的上传器中,我添加了

   @s3 = RightAws::S3Interface.new('MY KEY', 'MY SECRET KEY')
   @s3.put('my.bucket.com', assemble.photo.identifier ,params[:assemble][:photo])

感谢 Nishant 的帮助,CarrierWave 会更流畅、更好,但目前无法正常工作。在他们的 github 中有一个关于在 Rails 引擎中使用的问题。

于 2012-12-19T11:08:20.917 回答