简体   繁体   English

使用Carrierwave-aws gem,Rails4和Heroku时,为什么在Amazon S3中我的存储桶是空的

[英]Why is my bucket empty in Amazon S3, when using Carrierwave-aws gem, Rails4 and Heroku

I am trying to upload images to Amazon S3, but they stay on Heroku only. 我正在尝试将图像上传到Amazon S3,但它们仅保留在Heroku What should I put in config.asset_host in the carrierwave.rb , when using the Carrierwave-aws gem? 使用Carrierwave-aws gem时,应该在carrierwave.rb中的config.asset_host中放入什么?

This is my uploaders -> pictureuploader.rb 这是我的上传器-> pictureuploader.rb

class PictureUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick

   include CarrierWave::MiniMagick
   version :thumb do
  process :resize_to_fill => [150, 150]
end

  # Choose what kind of storage to use for this uploader:
  storage :file
  # storage :fog

   def cache_dir
    "#{Rails.root}/tmp/uploads"
  end

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

  # Provide a default URL as a default if there hasn't been a file uploaded:
   def default_url
       ActionController::Base.helpers.asset_path("fallback/#{version_name || :thumb}/default.png")
   end



  # Add a white list of extensions which are allowed to be uploaded.
  # For images you might use something like this:
   def extension_white_list
     %w(jpg jpeg gif png)
   end
end

This is my config -> initializers -> carrierwave.rb 这是我的配置->初始化-> carrierwave.rb

CarrierWave.configure do |config|
  config.storage    = :aws
  config.aws_bucket = ENV['S3_BUCKET_NAME']
  config.aws_acl    = :public_read
  config.asset_host = ''
  config.aws_authenticated_url_expiration = 60 * 60 * 24 * 365


  config.aws_credentials = {
    access_key_id:     ENV['AWS_ACCESS_KEY_ID'],
    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
  }
end

I'm using the Figaro gem to store the Amazon S3 credentials and have the file in .gitignore. 我正在使用Figaro gem来存储Amazon S3凭据,并将文件保存在.gitignore中。 I have done >> rake figaro:heroku 我已经完成>> rake figaro:heroku

My gemfile: 我的gemfile:

source 'https://rubygems.org'
ruby '2.0.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'


# Use sqlite3 as the database for Active Record
group :development, :test do
  gem 'sqlite3'
end

group :production do
  gem 'pg'
end

gem 'carrierwave'

gem 'carrierwave-aws'

gem 'figaro'

gem 'aws-sdk'

gem 'mini_magick', '3.5.0'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

gem 'bootstrap-sass', '2.3.2.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

group :test, :development do
  gem "rspec-rails", "2.13.1"
end

group :test do
  gem "capybara", "2.1.0"
end

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

In my event.rb model, I have added: 在我的event.rb模型中,我添加了:

    require 'carrierwave/orm/activerecord'
mount_uploader :image_file_name, PictureUploader

And in my show.html.erb view I have: 在我的show.html.erb视图中,我有:

<%= image_tag(@event.image_file_name_url, :width => 400) if @event.image_file_name.present? %>

I can upload images, but on my Amazon AWS console, it says that my bucket is empty. 我可以上传图像,但是在我的Amazon AWS控制台上,它说我的存储桶是空的。 So currently they only stay on Heroku ? 所以目前他们只留在Heroku吗? What could I try next? 接下来我可以尝试什么?

I managed to get this to work by changing the storage option to :aws and changing in production.rb the 我设法通过将存储选项更改为:aws并在production.rb中进行了更改来使其工作

config.action_controller.asset_host = " https://s3-us-west-1.amazonaws.com/mybucketname " config.action_controller.asset_host =“ https://s3-us-west-1.amazonaws.com/mybucketname

So now this question is solved, since the bucket is not empty any more. 因此现在解决了这个问题,因为存储桶不再是空的。

However now I have a new issue, CSS doesn't load on Heroku, when I enabled an asset server (AWS) to serve images? 但是现在有了一个新问题, 当我启用资产服务器(AWS)来提供图像时CSS无法在Heroku上加载吗? Using Rails4, Carrierwave, Heroku, Amazon S3 since my solution broke the CSS. 自从我的解决方案破坏了CSS以来,就使用了Rails4,Carrierwave,Heroku,Amazon S3

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我启用资产服务器(AWS)提供图像时,Heroku上没有加载CSS? 使用Rails4,Carrierwave,Heroku,Amazon S3 - CSS doesn't load on Heroku, when I enabled an asset server (AWS) to serve images? Using Rails4, Carrierwave, Heroku, Amazon S3 Rails 4,Carrierwave-aws,图像在本地上传到Amazon s3,但不在生产中(Openshift) - Rails 4, Carrierwave-aws, images uploaded to Amazon s3 locally, but not in production (Openshift) 使用Amazon S3配置Carrierwave,在Heroku上托管 - Configuration for Carrierwave with Amazon S3, hosted on Heroku rails4 carrierwave + S3添加新图像版本 - rails4 carrierwave + S3 adding new image version 我设置了我的AWS密钥,它们显示在linux终端中,但是Rails 4应用程序找不到它们。 使用aws-sdk和carrierwave-aws宝石 - I set my AWS keys and they show up in linux terminal, but Rails 4 app can't find them. Using aws-sdk and carrierwave-aws gems Carrierwave,Fog,Amazon S3,Rails 4 - Carrierwave, Fog, Amazon S3, Rails 4 使用s3_direct_upload Gem的AWS S3似乎正在处理,但没有任何内容上传到我的s3存储桶 - AWS S3 using s3_direct_upload Gem appears to process but nothing is uploaded to my s3 bucket Rails使用aws-sdk gem和heroku上的jQuery-File-Upload直接进入S3上传 - Rails direct to S3 upload using aws-sdk gem and jQuery-File-Upload on heroku 如何使用Rails将图片从Amazon s3存储桶获取到本地系统? - How can I take image from the amazon s3 bucket to my local system using rails? Rails 4 Carrierwave,Amazon S3,雾度错误 - Rails 4 Carrierwave, Amazon S3, Fog error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM