我无法将图像上载到AWSS3存储桶我在我的终端上得到这个:app/controllers/restaurants\u controller.rb:40:in‘block in update’

uttx8gqw  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(260)

图像显示在s3存储桶中,但是当我尝试上传它们时,网页页面没有显示任何活动,最终我在终端中得到了上面提到的错误。
这是我关于ror的第一个项目(或者是编码项目),我有点被这个问题困扰。以下是我的终端上的输出。

Processing by RestaurantsController#show as HTML
  Parameters: {"id"=>"1"}
  Restaurant Load (0.2ms)  SELECT "restaurants".* FROM "restaurants" WHERE "restaurants"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/restaurants_controller.rb:62:in `set_restaurant'
  Rendering layout layouts/application.html.erb
  Rendering restaurants/show.html.erb within layouts/application
Started GET "/restaurants/1" for ::1 at 2021-07-18 10:51:38 +0530
Processing by RestaurantsController#show as HTML
  Parameters: {"id"=>"1"}
   (0.1ms)  SELECT sqlite_version(*)
  ↳ app/controllers/restaurants_controller.rb:62:in `set_restaurant'
  Restaurant Load (0.8ms)  SELECT "restaurants".* FROM "restaurants" WHERE "restaurants"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/restaurants_controller.rb:62:in `set_restaurant'
  Rendering layout layouts/application.html.erb
  Rendering restaurants/show.html.erb within layouts/application
[fog][WARNING] Unable to fetch credentials: connect_write timeout reached
  TRANSACTION (0.3ms)  begin transaction
  ↳ app/controllers/restaurants_controller.rb:40:in `block in update'
  Restaurant Update (1.3ms)  UPDATE "restaurants" SET "updated_at" = ?, "image" = ? WHERE "restaurants"."id" = ?  [["updated_at", "2021-07-18 05:22:38.953124"], ["image", "dislike.png"], ["id", 1]]
  ↳ app/controllers/restaurants_controller.rb:40:in `block in update'
  TRANSACTION (0.9ms)  commit transaction
  ↳ app/controllers/restaurants_controller.rb:40:in `block in update'
[fog][WARNING] Unable to fetch credentials: connect_write timeout reached
  TRANSACTION (0.1ms)  begin transaction
  ↳ app/controllers/restaurants_controller.rb:40:in `block in update'
  Restaurant Update (7.4ms)  UPDATE "restaurants" SET "updated_at" = ?, "image" = ? WHERE "restaurants"."id" = ?  [["updated_at", "2021-07-18 05:26:07.066759"], ["image", "comment.png"], ["id", 1]]
  ↳ app/controllers/restaurants_controller.rb:40:in `block in update'
  TRANSACTION (6.3ms)  commit transaction
  ↳ app/controllers/restaurants_controller.rb:40:in `block in update'

这是我的型号/上传器/image_uploader.rb

class ImageUploader < CarrierWave::Uploader::Base
  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  # include CarrierWave::MiniMagick

  # 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

end

这是我的show.html.erb文件

<p id="notice"><%= notice %></p>

  <%= image_tag @restaurant.image_url %>

<p>
  <strong>Name:</strong>
  <%= @restaurant.name %>
</p>

<p>
  <strong>Address:</strong>
  <%= @restaurant.address %>
</p>

<p>
  <strong>Phone:</strong>
  <%= @restaurant.phone %>
</p>

<p>
  <strong>Website:</strong>
  <%= @restaurant.website %>
</p>

<%= link_to 'Edit', edit_restaurant_path(@restaurant), class: "btn btn-link"  %> |
<%= link_to 'Back', restaurants_path, class: "btn btn-link"  %>

我的档案

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.0.0'

gem 'rails', '~> 6.1.4'
gem 'sqlite3', group: :development
gem 'puma', '~> 5.0'
gem 'sass-rails', '>= 6'
gem 'webpacker', '~> 5.0'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.7'
gem 'rails_12factor', group: :production
gem 'pg', group: :production
gem 'carrierwave'
gem "fog-aws"

gem 'bootsnap', '>= 1.4.4', require: false

group :development, :test do
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  gem 'web-console', '>= 4.1.0'
  gem 'rack-mini-profiler', '~> 2.0'
  gem 'listen', '~> 3.3'
  gem 'spring'
end

group :test do
  gem 'capybara', '>= 3.26'
  gem 'selenium-webdriver'
  gem 'webdrivers'
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

还有我的carrierwave.rb文件

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider:              'AWS',                        # required
    aws_access_key_id:     'accessKey',                        # required unless using use_iam_profile
    aws_secret_access_key: 'secretKey',                        # required unless using use_iam_profile
    use_iam_profile:       true,                         # optional, defaults to false
    region:                'ap-south-1',                  # optional, defaults to 'us-east-1'

  }
  config.fog_directory  = 's3bucketname'                                      # required
  config.fog_public     = false                                                 # optional, defaults to true
  config.fog_attributes = { cache_control: "public, max-age=#{365.days.to_i}" } # optional, defaults to {}

end

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题