我已經構建了一個應用程序,部署在heroku上,使用carrierwave保存所有上傳的文件,我爲開發者設置了谷歌存儲空間在那裏保存這些文件。Rails - 隱藏用戶的文件url(rails 3.1 + carrierwave +谷歌存儲爲開發者)
直到這裏一切工作正常,但我想保持文件顯示私人,即。用戶必須有權查看。 在開發環境中一切正常。
爲了用戶隱藏文件源URL我做出以下決定:
初始化/ carrierwave.rb
CarrierWave.configure do |config|
if Rails.env.production?
config.storage = :fog
config.fog_credentials = {
:provider => 'Google',
:google_storage_access_key_id => 'xxx',
:google_storage_secret_access_key => 'yyy'
}
config.fog_directory = 'wwww'
else
config.storage = :file
end
end
控制器
這得到了文件內容爲了躲避公衆的眼睛和名字
def get_file
if Rails.env.production?
redirect_to URI.encode @media_asset.attachment_url
else
send_file ("public/"[email protected]_asset.attachment_url.to_s),
:type => @media_asset.attachment_content_type,
:length => @media_asset.attachment_file_size,
:status => "200 OK",
:x_sendfile => true,
:filename => "media_asset",
:disposition => 'inline'
end
end
顯然這會做這項工作,但使用普通的瀏覽器開發工具,每個人都會看到谷歌存儲桶的路徑,並能夠訪問所有文件。
對於如何解決這個問題,你有線索嗎?是否有可能爲開發者提供谷歌存儲?
在此先感謝,
這個想法是有應用程序帳戶。我實際上使用設計作爲認證寶石,稍後的目標是有多個登錄選項,如Facebook,Twitter,谷歌等......但目前所有重要的是有應用程序的用戶。 – brunomac 2012-02-01 09:53:59
我切換到S3,我仍然在解決這個問題。 – brunomac 2012-02-02 13:42:19
雖然答案其實不對,但我會接受它,因爲我想轉移到另一個雲存儲提供商。 – brunomac 2012-02-03 15:09:02