asset_sync未上传到S3

时间:2013-10-07 21:00:44

标签: ruby-on-rails heroku amazon-s3 asset-sync

使用asset_sync

将资产上传到S3时遇到问题

production.rb

config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3-eu-west-1.amazonaws.com"
config.assets.digest = true
config.assets.enabled = true
config.assets.initialize_on_precompile = true

asset_sync.rb

if defined?(AssetSync)

 AssetSync.configure do |config|
  config.fog_provider = 'AWS'
  config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
  config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
  config.fog_directory = ENV['FOG_DIRECTORY']
  config.fog_region = 'eu-west-1'

 end
end

heroku config

AWS_ACCESS_KEY_ID:   XXX
AWS_SECRET_ACCESS_KEY: XXX
FOG_DIRECTORY: bucket_name
FOG_PROVIDER:  AWS
FOG_REGION: 'eu-west-1'

$出口

declare -x AWS_ACCESS_KEY_ID= XXX
declare -x AWS_SECRET_ACCESS_KEY= XXX
declare -x FOG_DIRECTORY="bucket_name"
declare -x FOG_PROVIDER="AWS"

http://blog.firmhouse.com/complete-guide-to-serving-your-rails-assets-over-s3-with-asset_sync

将heroku资产点数推到//bucket_name.s3-eu-west-1.amazonaws.com/assets/icons/name_xxxxxxxxxx.png 并且在运行$rake assets:precompile时,文件无法上传到S3并且只在本地进行预编译。任何的想法 ?非常感谢。

编辑:

我刚刚更改了Gemfile:

  group :assets do
   gem 'asset_sync'
  end

到全球宝石

 gem 'asset_sync'

现在我收到了警告信息[WARNING] fog: followed redirect to bucket_name.s3-external-3.amazonaws.com, connecting to the matching region will be more performant

我想我可以解决这个问题,但只有css文件被上传。不是js文件和图片。

1 个答案:

答案 0 :(得分:1)

您的bucket_name需要成为S3上的存储桶

您应该更改以下命令:

Heroku
FOG_DIRECTORY: your_bucket_real_name

Local
declare -x FOG_DIRECTORY=your_bucket_real_name

此外,您应该在production.rb文件中更改此内容:

config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"

我认为这将解决您的问题。我在EU-West上使用S3具有完全相同的设置(禁止我引用的差异),并且它在大部分工作:)