Home>
Contents

I'm trying to deploy on AWS. I am making a site where I can post images using S3, but the posted images are not displayed as shown below. Looking at the console of Google's developer tools, it says "Failed to load resource: the server responded with a status of 404 ()".
I think the image has been uploaded to S3 itself and I just can't load it, but I don't know where to fix it, so please let me know.

When you click the image URL of resource: the server responded with a status of 404 () microposts.rb
class Micropost</pre>
<strong>image_uploader.rb</strong>
<pre><code>class ImageUploader<CarrierWave :: Uploader :: Base
  include CarrierWave :: MiniMagick
  require'mini_magick'
  #Include RMagick or MiniMagick support:
  #include CarrierWave :: RMagick
  if Rails.env.production?
    include Cloudinary :: CarrierWave
  else else
    storage: fog
  end
  #Choose what kind of storage to use for this uploader:
  # storage: file
  storage: fog
  #Override the directory where uploaded files will be stored.
  #This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/# {model.class.to_s.underscore}/# {mounted_as}/# {model.id}"
  end
  #def default_url (* args)
   # ActionController :: Base.helpers.asset_path ("fallback /" + [version_name, "default.png"]. compact.join ('_'))
  #Provide a default URL as a default if there hasn't been a file uploaded:
  #def default_url (* args)
  # # For Rails 3.1+ asset pipeline compatibility:
  # # ActionController :: Base.helpers.asset_path ("fallback /" + [version_name, "default.png"]. compact.join ('_'))
  #
  # "/ images/fallback /" + [version_name, "default.png"] .compact.join ('_')
  # end
  #Process files as they are uploaded:
  #process scale: [200, 300]
  #
  #def scale (width, height)
  # # do something
  # end
  #Create different versions of your uploaded files:
  # version: thumb do
  # process resize_to_fit: [50, 50]
  # end
  #Add a white list of extensions which are allowed to be uploaded.
  # For images you might use something like this:
  def extension_whitelist
     % w (jpg jpeg gif png)
  end
  #Override the filename of the uploaded files:
  # Avoid using model.id or version_name here, see uploader/store.rb for details.
  # def filename
  # "something.jpg" if original_filename
  # end
  process resize_to_fill: [300, 300, "Center"]
end
The part where the image is displayed in _micropost.html.erb
<% if micropost.image?%>
<% = image_tag micropost.image.to_s, class: "micropost_image"%>
<% else%>
<% = image_tag'no_image.png', class: "micropost_image"%>
<% end%>
config/initializers/carrierwave.rb (key has changed slightly)
require'carrierwave/storage/abstract'
require'carrierwave/storage/file'
require'carrierwave/storage/fog'
CarrierWave.configure do | config |
  config.storage =: fog
  config.fog_provider ='fog/aws'
  config.fog_credentials = {
    provider:'AWS',
    aws_access_key_id:'AKIAQFS7xxxZ6FWVOKW6',
    aws_secret_access_key: "/ + 0I953xxxxVNJtM/3s3gYlWUPd + rB8xxxkvN8ig",
    region:'ap-northeast-1'
  }
  config.fog_directory ='bucketrugby'
  config.asset_host ='http://bucketrugby.s3-ap-northeast-1.amazonaws.com'
end