2011-09-23 99 views
0

我在Heroku上有一個應用程序,它使用Carrierwave將圖像上傳到S3。該應用程序是在本地機器上運行完美,但在Heroku上引發以下錯誤和失敗上傳到S3:Carrierwave + Fog(S3)+ Heroku:TypeError(無法將哈希轉換爲字符串)

TypeError (can't convert Hash into String): 
2011-09-23T15:12:07+00:00 app[web.1]: app/controllers/admin/albums_controller.rb:49:in `create' 
2011-09-23T15:12:07+00:00 app[web.1]: app/controllers/admin/albums_controller.rb:48:in `create' 

該行對應於「如果@ album.save」指令。

我的專輯控制器創建行動:

def create 
@album = Album.new(params[:album]) 

respond_to do |format| 
    if @album.save 
    format.html { redirect_to(admin_album_path(@album), :notice => 'Àlbum creat correctament.') } 
    format.xml { render :xml => [:admin, @album], :status => :created, :location => @album } 
    else 
    format.html { render :action => "new" } 
    format.xml { render :xml => @album.errors, :status => :unprocessable_entity } 
    end 
end 
end 

我Carrierwave初始化:

CarrierWave.configure do |config| 
    config.fog_credentials = { 
     :provider    => 'AWS', 
     :aws_access_key_id  => APP_CONFIG['storage']['s3_access'], 
     :aws_secret_access_key => APP_CONFIG['storage']['s3_secret'], 
    } 
    config.fog_directory = 'romeu' 
    config.fog_host  = 'http://xxxxx.s3.amazonaws.com' 
    config.fog_public  = true 
    config.root = Rails.root.join('tmp') 
    config.cache_dir = 'carrierwave' 
end 

我image_uploader.rb:

class ImageUploader < CarrierWave::Uploader::Base 

include CarrierWave::MiniMagick 

storage :fog 

def store_dir 
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
end 

# Album Cover version 
version :cover do 
    process :square_resize => [150,150] 
end 

# Thumb version 
version :thumb do 
    process :square_crop => [80,80] 
end 

def square_crop(width, height) 
    manipulate! do |img| 
    side = [img['width'], img['height']].min 
    x = (img['width'] - side)/2 
    y = (img['height'] - side)/2 
    img.crop("#{side}x#{side}+#{x}+#{y}") 
    img.resize("#{width}x#{height}") 
    img 
    end 
end 

def square_resize(width, height) 
    manipulate! do |img| 
    img.resize("#{width}x#{height}") 
    img 
    end 
end 

# Valid list 
def extension_white_list 
    %w(jpg jpeg gif png) 
end 
end 

我config.ru:

# This file is used by Rack-based servers to start the application. 

require ::File.expand_path('../config/environment', __FILE__) 
use Rack::Static, :urls => ['/carrierwave'], :root => 'tmp' 
run Encen::Application 

我已檢查了@album對象,一切似乎好:

_mounters: 
    :image: !ruby/object:CarrierWave::Mount::Mounter 
    _memoized_option: 
     ? 
     - :mount_on 
     : 

    column: :image 
    integrity_error: 
    options: {} 

    processing_error: 
    record: *id001 
    uploader: !ruby/object:ImageUploader 
     cache_id: 20110923-0810-1-0644 
     file: !ruby/object:CarrierWave::SanitizedFile 
     content_type: image/jpeg 
     file: /app/tmp/carrierwave/20110923-0810-1-0644/image.jpg 
     original_filename: 
     filename: image.jpg 
     model: *id001 
     mounted_as: :image 
     original_filename: image.jpg 
     versions: 
     :thumb: !ruby/object: 
      file: !ruby/object:CarrierWave::SanitizedFile 
      cache_id: 20110923-0810-1-0644 
      content_type: image/jpeg 
      file: /app/tmp/carrierwave/20110923-0810-1-0644/image.jpg 
      original_filename: 
      filename: image.jpg 
      model: *id001 
      mounted_as: :image 
      original_filename: image.jpg 
      parent_cache_id: 20110923-0810-1-0644 
      versions: {} 

     :cover: !ruby/object: 
      cache_id: 20110923-0810-1-0644 
      file: !ruby/object:CarrierWave::SanitizedFile 
      content_type: image/jpeg 
      file: /app/tmp/carrierwave/20110923-0810-1-0644/image.jpg 
      original_filename: 
      filename: image.jpg 
      model: *id001 
      mounted_as: :image 

attributes: 

    title: 
    body: 
    model: *id001 
previously_changed: {} 
readonly: false 

我花了一堆天打算解決這一錯誤,但不成功的,有什麼我失蹤? 在此先感謝。

+0

嘗試更改http爲https for fog_directory,這是他們如何在文檔中它https://github.com/jnicklas/carrierwave – Hishalv

+0

我認爲你指的是fog_host而不是fog_directory,但我已經嘗試過,我有一樣的問題。現在我想知道如果我在Amazon S3上設置了正確的權限,那麼您對什麼是正確的配置有任何疑問嗎?謝謝 –

回答

0

經過長時間的挫折,我解決了這個問題。這就像一個愚蠢的事情,就像Heroku上的S3訪問鍵的環境變量被錯誤地定義一樣。我不明白爲什麼霧寶石不會給你更準確的關於這類錯誤的調試信息。

相關問題