gpt4 book ai didi

ruby-on-rails - 带有 Amazon S3 的 Carrierwave 配置,托管在 Heroku 上

转载 作者:行者123 更新时间:2023-12-04 05:47:45 24 4
gpt4 key购买 nike

我遵循了 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 文件,但没有成功。

下面是载波初始值设定项, key 已编辑。

这是正确设置吗?

我还需要做什么?

任何分步指南可以帮助我实现这一点?

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

最佳答案

你生成了上传文件吗?
rails generate uploader Avatar
这将生成如下文件:
应用程序/上传者/avatar_uploader.rb
class AvatarUploader < CarrierWave::Uploader::Base
存储:文件
结尾

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

这是我的文件
配置/初始化程序/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

我还向您推荐这个railcasts:

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

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

关于ruby-on-rails - 带有 Amazon S3 的 Carrierwave 配置,托管在 Heroku 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17264658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com