2014-02-13 24 views
2

我需要配置我在Amazon S3上的圖像,但是當我試圖這樣做下的版本2-2穩定施普雷,我意識到,此配置已從管理面板移開。如何使用Amazon S3上狂歡-2-2-穩定

我在某處讀到這個配置產生了一些問題,因此它在2-2上被刪除。但我認爲功能仍在某種程度上起作用。

當我嘗試將這些配置添加到我的config/initialize/spree.rb時,出現錯誤,因爲這些首選項已不存在。

preference :s3_access_key, :string 
preference :s3_bucket, :string 
preference :s3_secret, :string 

這些首在2-1穩定,但沒有發現在2-2穩定

https://github.com/spree/spree/blob/2-1-stable/core/app/models/spree/app_configuration.rb https://github.com/spree/spree/blob/2-2-stable/core/app/models/spree/app_configuration.rb

有什麼辦法如何得到它才能使用它的工作和Heroku一起?

回答

6

以下是Spree提交的更改以及有關如何進行配置更改的一些說明。 https://github.com/spree/spree/commit/b1d6c5e4b9801d888cc76c05116b814945122207

我的理解是,你仍然可以使用回形針來管理上傳到S3,我已經成功地完成了使用他們的指示。然而,我在S3上的保存路徑正確配置時遇到了問題。這可能讓你開始...在一個環境配置文件把下面的:

# Paperclip configs 
    config.paperclip_defaults = { 
     :storage => :s3, 
     :bucket => ENV['S3_BUCKET_NAME'], 
     :s3_credentials => { 
      :access_key_id => ENV['AWS_ACCESS_KEY_ID'], 
      :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'] 
     } 
    } 

我使用環境變量的S3憑據,所以你將最有可能是不同的。這段代碼已經使上傳文件到S3工作,就像我說的我只是無法強制上傳一個特定的文件路徑。希望有所幫助。

編輯 - 附加信息:

添加以下到spree.rb初始化定義自定義上傳路徑和自定義URL路徑。

# S3 upload path and url path configuration 
Spree::Image.attachment_definitions[:attachment][:path] = 'products/:id/:style/:basename.:extension' 
Spree::Image.attachment_definitions[:attachment][:url] = 'products/:id/:style/:basename.:extension' 

要更改默認上傳大小,您可以覆蓋Spree圖像裝飾模型。因此,在app/models下添加一個spree目錄並添加一個名爲image_decorator.rb的文件。然後,您可以用下面的控制大小:

Spree::Image.class_eval do 
    attachment_definitions[:attachment][:styles] = { 
    :mini => '48x48>', # thumbs under image 
    :small => '350x700>', # images on category view 
    :product => '1024x768>', # full product image 
    :large => '600x600>' # light box image 
    } 
end 

查看此頁面的具體要求 - >http://guides.spreecommerce.com/developer/logic.html

所以總結起來,可以通過更新你的環境做你的所有普通圖像/ S3配置初始值設定項,Spree初始值設定項和覆蓋spree image_decorator模型。

+0

非常感謝您的答覆。我將在未來嘗試一下,但是現在我決定採用2-1穩定的方式,並且在那裏正常運轉。 – gobeltri

+0

非常感謝您爲我工作。 – Ghar