前提・実現したいこと
railsで本番環境の画像アップロードをしたい。
画像アップロードをすると以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
Excon::Error::BadRequest in UsersController#update Expected(200) <=> Actual(400 Bad Request) excon.error.response :body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AuthorizationHeaderMalformed</Code><Message>The authorization header is malformed; the Credential is mal-formed; expecting \"<YOUR-AKID>/YYYYMMDD/REGION/SERVICE/aws4_request\".</Message><RequestId>FA6D5E9A8FF746E2</RequestId><HostId>EtSsgNaPIm8kLD32SQjjyrqKH1cNTP4Npr3IPLj29GDxkKh/evNYtT3TiP12qiymKPvcLfLJqbg=</HostId></Error>" :cookies => [ ] :headers => { "Connection" => "close" "Content-Type" => "application/xml" "Date" => "Tue, 28 Jan 2020 10:40:27 GMT" "Server" => "AmazonS3" "x-amz-id-2" => "EtSsgNaPIm8kLD32SQjjyrqKH1cNTP4Npr3IPLj29GDxkKh/evNYtT3TiP12qiymKPvcLfLJqbg=" "x-amz-request-id" => "FA6D5E9A8FF746E2" }
該当のソースコード
ruby
1CarrierWave.configure do |config| 2 if Rails.env.development? || Rails.env.test? #開発とテストは今まで通りに 3 config.storage = :file 4 elsif Rails.env.production? #本番はS3に保存する 5 config.storage = :fog 6 config.fog_provider = 'fog/aws' 7 config.fog_credentials = { 8 provider: 'AWS', 9 aws_access_key_id: Rails.application.credentials.aws[:access_key_id], 10 aws_secret_access_key: Rails.application.credentials.aws[:secret_access_key], 11 region: 'ap-northeast-1' 12 } 13 14 config.fog_directory = 'a' 15 config.asset_host = 'https://s3-ap-northeast-1.amazonaws.com/a' 16 end 17end 18 19 20users_contoroller.rb 21 22class UsersController < ApplicationController 23 def show 24 @user = User.find(params[:id]) 25 @posts = @user.posts 26 end 27 28 def edit 29 @user = User.find(params[:id]) 30 end 31 def update 32 @user = User.find(params[:id]) 33 if @user.update(user_params) 34 flash[:notice] = "変更を保存しました" 35 redirect_to user_path(current_user) 36 else 37 flash[:alert] = "編集の保存に失敗しました" 38 render :edit 39 end 40 end 41 42 private 43 44 def user_params 45 params.require(:user).permit(:nickname, :email, :image) 46 end 47 48end 49 50users/view/edit.html.haml 51 52.profile__right__content__edit 53 = form_with model: @user, local: true do |f| 54 = f.label :image, class: "file", id: 'user_img' do 55 -if @user.image.present? 56 .profile-content__edit__view-box 57 = image_tag @user.image.to_s, alt: "プロフィール画像",size: "60x60", class: 'mypage__icon', id: :img_prev 58 .profile-content__edit__nickname 59 = f.text_field :nickname, class: 'profile__right__input__nickname',value: @user.nickname 60 .profile-content__edit__email 61 = f.email_field :email, class: 'profile__right__input__email' 62 .profile-content__edit__password 63 = f.password_field :password 64 新しいパスワード 65 .profile-content__edit__password-confirmation 66 = f.password_field :password_confirmation 67 新しいパスワード確認 68 -else 69 .profile-content__edit__view-box 70 -# = image_tag "noimage.jpeg", alt: "プロフィール画像",size: "60x60", class: 'mypage__icon' 71 .profile-content__edit__nickname 72 = f.text_field :nickname, class: 'profile__right__input__nickname',value: @user.nickname 73 .profile-content__edit__email 74 = f.email_field :email, class: 'profile__right__input__email' 75 .profile-content__edit__password 76 = f.password_field :password 77 新しいパスワード 78 .profile-content__edit__password-confirmation 79 = f.password_field :password_confirmation 80 新しいパスワード確認 81 = f.file_field :image,class: 'file' 82 .profile__right__content__bottom 83 .profile__right__content__profile 84 = f.submit '変更する', class: 'profile__right__input__send'
試したこと
エラー文で検索をかけたがENVの情報ばかりで解決できなかった。
補足情報(FW/ツールのバージョンなど)
rails 5.2.4.1
必要なファイルなどの情報は言ってもらえれば載せさして頂きます。
どうかよろしくお願いします。
回答2件
あなたの回答
tips
プレビュー