画像保存をAWSのS3に保存しているのですが、本番環境で保存できて、ローカル環境で保存できない自体が発生しました。もしかするとS3は関係ない可能性もあると思いますがよろしくお願いします。
せめてどこが関係するエラーなのかでも知りたいです
####発生するエラー
Failed to load resource: the server responded with a status of 422 (Unprocessable Entity)
######binding.pryでimageの中身を確認
=> <ActionController::Parameters {"image"=>#<ActionDispatch::Http::UploadedFile:0x00007ff610e5bfb0 @tempfile=#<Tempfile:/var/folders/jx/2hgkcf7j7fn7zcwnqr__yxr80000gn/T/RackMultipart20210522-1488-1czwkh4.jpg>, @original_filename="IMG_z3om5u.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"image\"; filename=\"IMG_z3om5u.jpg\"\r\nContent-Type: image/jpeg\r\n">,
環境変数は間違えてなかったです
######関連しそうなファイル
carriawave
1require 'carrierwave/storage/abstract' 2require 'carrierwave/storage/file' 3require 'carrierwave/storage/fog' 4 5CarrierWave.configure do |config| 6 # if Rails.env.development? || Rails.env.test? 7 # elsif Rails.env.production? 8 config.storage = :fog 9 config.fog_provider = 'fog/aws' 10 config.fog_credentials = { 11 provider: 'AWS', 12 aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'], 13 aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], 14 region: 'ap-northeast-1' 15 } 16 17 config.fog_directory = 'rails-baseball-app' 18 config.asset_host = 'https://s3-ap-northeast-1.amazonaws.com/rails-baseball-app' 19 end
imageuploader
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 storage :fog 8 # storage :file 9 10 # Override the directory where uploaded files will be stored. 11 # This is a sensible default for uploaders that are meant to be mounted: 12 def store_dir 13 "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 14 end 15 include CarrierWave::MiniMagick 16 process resize_to_fit: [400, 400] 17 # Provide a default URL as a default if there hasn't been a file uploaded: 18 # def default_url(*args) 19 # # For Rails 3.1+ asset pipeline compatibility: 20 # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) 21 # 22 # "/images/fallback/" + [version_name, "default.png"].compact.join('_') 23 # end 24 25 # Process files as they are uploaded: 26 # process scale: [200, 300] 27 # 28 # def scale(width, height) 29 # # do something 30 # end 31 32 # Create different versions of your uploaded files: 33 # version :thumb do 34 # process resize_to_fit: [50, 50] 35 # end 36 37 # Add a white list of extensions which are allowed to be uploaded. 38 # For images you might use something like this: 39 # def extension_whitelist 40 # %w(jpg jpeg gif png) 41 # end 42 43 # Override the filename of the uploaded files: 44 # Avoid using model.id or version_name here, see uploader/store.rb for details. 45 # def filename 46 # "something.jpg" if original_filename 47 # end 48end
回答1件
あなたの回答
tips
プレビュー