5

我已按照 Carrierwave 的部署说明,了解如何使用 Amazon S3 在 Heroku 上部署 Rails 应用程序:

https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Make-Carrierwave-work-on-Heroku

我已将额外的行添加到 config.ru 并创建了 config/initializers/carrierwave.rb 文件,但没有成功。

下面是载波初始化器,其中的键已被编辑。

这是正确设置吗?

我还需要做什么?

有什么分步指南可以帮助我实现这一点吗?

CarrierWave.configure do |config|
config.fog_credentials = {
:provider               => 'AWS',                        # required
:aws_access_key_id      => REDACTED,                     # required
:aws_secret_access_key  => REDACTED,                     # required
:region                 => 'eu-west-1',                  # optional, defaults to 'us-east-1'
:host                   => 's3.example.com',             # optional, defaults to nil
:endpoint               => 'https://s3.example.com:8080' # optional, defaults to nil
}
config.fog_directory  = 'myawsbucket'                  # required
config.fog_public     = false                                   # optional, defaults to true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  # optional, defaults to {}
end
4

1 回答 1

7

您是否生成了上传文件?

rails generate uploader Avatar

这将生成一个像这样的文件: app/uploaders/avatar_uploader.rb class AvatarUploader < CarrierWave::Uploader::Base storage :file end

入门中的更多信息https://github.com/carrierwaveuploader/carrierwave 。

这是我的文件 config/initializers/carrierwave.rb

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',
    :aws_access_key_id      => 'REDACTED',
    :aws_secret_access_key  => 'REDACTED'
  }
  config.fog_directory  = "myawsbucket"
end

应用程序/上传程序/amazon_uploader.rb

class AmazonUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  include Sprockets::Helpers::RailsHelper
  include Sprockets::Helpers::IsolatedHelper

  storage :fog

  include CarrierWave::MimeTypes
  process :set_content_type

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

  version :user_thumb do
    process :resize_to_limit => [200, 200]
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end
end

我还向您推荐这个铁路广播:

http://railscasts.com/episodes/253-carrierwave-file-uploads

http://railscasts.com/episodes/383-uploading-to-amazon-s3

于 2013-06-24T03:57:21.967 回答