私は、現在S3を使って、画像を表示したいと考えています。しかし、URI::InvalidURIError (bad URI(is not URI?): https://s3-ap-northeast-1 .amazonaws.com:443):のエラーが発生してしまい、動かない状態になっています。もしわかる方がいらしたら、どうぞ教えて頂きたいです。
config/initializers/carrierwave.rb
carrierwave
1require 'carrierwave/storage/abstract' 2require 'carrierwave/storage/file' 3require 'carrierwave/storage/fog' 4 5if Rails.env.production? 6CarrierWave.configure do |config| 7 config.fog_provider = 'fog/aws' 8 config.fog_credentials = { 9 provider: 'AWS', 10 aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'], 11 aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], 12 region: ENV['AWS_REGION'], 13 path_style: true 14 } 15 config.fog_public = true # public-read 16 17 config.remove_previously_stored_files_after_update = false 18 19 config.fog_directory = ENV['AWS_S3_BUCKET'] 20 config.asset_host = ENV['AWS_S3_URL'] 21 22end 23CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:].\-+]/ 24end
plans/new
view
1<div class="contents graph"> 2 <%= form_tag('/plans', method: :post, :multipart => true) do %> 3 <h3> 4 投稿商品の詳細 5 </h3> 6 <input placeholder="タイトル" type="text" name="title" autofocus="true" required> 7 <input placeholder="著者名" type="string" name="place" autofocus="true" required> 8 <input placeholder="授業名" type="string" name="times" autofocus="true" required> 9 <%= select_tag :datetimes, options_for_select([["---"],["新品、未使用品"],["未使用品に近い"], ["目立った傷や汚れなし"],["やや傷や汚れあり"],["傷や汚れあり"], ["全体的に状態が悪い"]]) , class: "superpark" %> 10 <input placeholder="価格" type="string" name="price" autofocus="true" required> 11 <div class="field"> 12 <%= file_field_tag 'image' %> 13 <%= file_field_tag 'copy_image' %> 14 <%= file_field_tag 'third_image' %> 15 <%= file_field_tag 'fourth_image' %> 16 <%= file_field_tag 'five_image' %> 17 </div> 18 <textarea placeholder="商品の説明" name="contents" cols="30" rows="10"></textarea> 19 <input type="submit" value="送信"> 20 <% end %> 21</div> 22
controller
1def create 2 Plan.create(place: params[:place], image: params[:image], 3 copy_image: params[:copy_image], third_image: params[:third_image], 4 fourth_image: params[:fourth_image], five_image: params[:five_image], 5 title: params[:title], contents: params[:contents], times: params[:times], 6 price: params[:price], datetimes: params[:datetimes], category: [:category], 7 others: params[:others], guider_id: current_guider.id) 8 9end 10 11private 12def plan_params 13 params.permit(:datetimes, :place, :image, :copy_image, :thrid_image, 14 :fourth_image, :five_image, :title, :contents, :times, :category, :others) 15end
uploader
1class ImageUploader < CarrierWave::Uploader::Base 2 # Include RMagick or MiniMagick support: 3 include CarrierWave::RMagick 4 include CarrierWave::MiniMagick 5 6 # Choose what kind of storage to use for this uploader: 7 if Rails.env.development? 8 storage :file 9 elsif Rails.env.test? 10 storage :file 11 else 12 storage :fog 13 end 14 # storage :fog 15 16 # Override the directory where uploaded files will be stored. 17 # This is a sensible default for uploaders that are meant to be mounted: 18 def store_dir 19 "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 20 end 21 22 # Provide a default URL as a default if there hasn't been a file uploaded: 23 # def default_url(*args) 24 # # For Rails 3.1+ asset pipeline compatibility: 25 # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) 26 # 27 # "/images/fallback/" + [version_name, "default.png"].compact.join('_') 28 # end 29 process resize_to_fit: [700, 700] 30 # Process files as they are uploaded: 31 # process scale: [200, 300] 32 # 33 # def scale(width, height) 34 # # do something 35 # end 36 process :convert => 'jpg' 37 # Create different versions of your uploaded files: 38 version :thumb do 39 process resize_to_fit: [1000, 1000] 40 end 41 42 # Add a white list of extensions which are allowed to be uploaded. 43 # For images you might use something like this: 44 def extension_whitelist 45 %w(jpg jpeg gif png) 46 end 47 48 # Override the filename of the uploaded files: 49 # Avoid using model.id or version_name here, see uploader/store.rb for details. 50 def filename 51 super.chomp(File.extname(super))+'jpg' if original_filename.present? 52 end 53end 54

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/10/21 03:49
退会済みユーザー
2019/10/21 07:13
2019/10/21 09:10