2012-12-19 49 views
2
到S3

我創建一個導軌和rails new plugin my_plugin --mountableRails的引擎沒有上傳與Carrierwave

插件這是相當一些工作要弄清楚,但它應該將文件上傳到S3與carrierwave,但它說好,但沒有什麼是上傳

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://,所以我不明白爲什麼該行是必要的。

之後,它說'好吧,它已經完成',當我試圖檢查(與deamon)的文件,沒有什麼。

我錯過了什麼?或者CarrierWave和Rails可掛載引擎有問題嗎?

回答

0

好吧所以有CarrierWave有點問題。

我已經快速設置RightAws,現在它上傳到S3,我可以從我的deamon找到它。

在我上傳

我加

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

感謝您的幫助NISHANT,CarrierWave將是一個很大的雨衣和漂亮,但它現在不工作。在他們的github中存在一個關於Rails引擎中使用的問題。

1

在你photo_uploader.rb

評論存儲:文件,取消存儲:霧

# storage :file 
    storage :fog 

- 看看你fog.rb,它什麼這裏給出

不一致carrierwave#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 
+0

謝謝,忘了改變它生成上傳後,但仍然deamon呼籲幫助,因爲沒有什麼在S3 – Michael

+0

[2] pry(#)> @ s3.get('my.bucket.com', 'background.png') RightAws :: AwsError:NoSuchKey:指定的鍵不存在。 from /Users/dev/.rvm/gems/[email protected]_generator/gems/right_aws-3.0.4/lib/awsbase/right_awsbase.rb:562:in'request_info_impl' – Michael

+0

@Michael看看更新的答案。 fog.rb是否正確? – Nishant