前提
Active Strageを用いて画像をs3に保存したいのですが、エラーが発生し、先に進めません。
実現したいこと
Active Strageを用いて画像をs3に保存
発生している問題・エラーメッセージ
Aws::Errors::InvalidRegionError in HomeController#update Invalid `:region` option was provided. * Not every service is available in every region. * Never suffix region names with availability zones. Use "us-east-1", not "us-east-1a" Known AWS regions include (not specific to this service): af-south-1 ap-east-1 ap-northeast-1 ap-northeast-2 ap-northeast-3 ap-south-1 ap-southeast-1 ap-southeast-2 ap-southeast-3 ca-central-1 eu-central-1 eu-north-1 eu-south-1 eu-west-1 eu-west-2 eu-west-3 me-central-1 me-south-1 sa-east-1 us-east-1 us-east-2 us-west-1 us-west-2 cn-north-1 cn-northwest-1 us-gov-east-1 us-gov-west-1 us-iso-east-1 us-iso-west-1 us-isob-east-1 Extracted source (around line #11): 9 10 11 12 13 14 def update @user = current_user if @user.update(params.permit(:profile_image, :user_name, :self_introduce, :twitter_url, :youtube_url, :instagram_url, :self_introduce_movie_url)) flash[:notice] = "Profile was successfully updated." redirect_to "/" else
該当のソースコード
development.rb
1# ファイルをAmazon S3に保存する 2 config.active_storage.service = :amazon
strage.yml
1test: 2 service: Disk 3 root: <%= Rails.root.join("tmp/storage") %> 4 5local: 6 service: Disk 7 root: <%= Rails.root.join("storage") %> 8 9# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10amazon: 11 service: S3 12 access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 region: <%= Rails.application.credentials.dig(:aws, :s3, :region) %> 15 bucket: <%= Rails.application.credentials.dig(:aws, :s3, :bucket) %> 16 17
user.rb
1class User < ApplicationRecord 2 # Include default devise modules. Others available are: 3 # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 4 devise :database_authenticatable, :registerable, 5 :recoverable, :rememberable, :validatable 6 7 has_one_attached :profile_image 8end 9
profile.html.erb
1<% if flash[:notcie] %> 2<p class="notice"><%= flash[:notice] %></p> 3<% end %> 4<div class="profile"> 5 <div class="profile-form"> 6 <div class="profile-container"> 7 <%= form_with url: update_home_path, method: :post do |f| %> 8 <table> 9 <tr> 10 <th><%= f.label :profile_image ,"アイコン画像" %></th> 11 <td><%= f.file_field :profile_image, value: @user.profile_image %></td> 12 </tr> 13 <tr> 14 <th><%= f.label :user_name ,"名前", class: "username" %></th> 15 <td><%= f.text_field :user_name, value: @user.user_name %></td> 16 </tr> 17 <tr> 18 <th><%= f.label :self_introduce ,"自己紹介", class: "self_introduce" %></th> 19 <td><%= f.text_area :self_introduce, value: @user.self_introduce %></td> 20 </tr> 21 </table> 22 <ul class="profile-btn-content"> 23 <li><%= f.submit "更新", class: "profile-btn"%></li> 24 </ul> 25 <% end %> 26 </div> 27 </div> 28</div>
home_controller.rb
1lass HomeController < ApplicationController 2 def top 3 end 4 5 def profile 6 @user = current_user 7 end 8 9 def update 10 @user = current_user 11 if @user.update(params.permit(:profile_image, :user_name, :self_introduce, :twitter_url, :youtube_url, :instagram_url, :self_introduce_movie_url)) 12 flash[:notice] = "Profile was successfully updated." 13 redirect_to "/" 14 else 15 render 'profile' 16 end 17 end 18end
gemfile
1gem "aws-sdk-s3"
試したこと
EDITOR="vi" bin/rails credentials:editコマンドで値が間違っていないか何度も確認しましたが、間違っていませんでした。
新しくバケットを作成し、再度試してみましたが結果は変わりませんでした。
補足情報(FW/ツールのバージョンなど)
前は問題なく画像は保存できていたのですが、ある時間違って途中段階の開発をリモートブランチにpushする前に消してしまい、ほぼ最初から開発を行なっています。そして再度Activi Strageを用いで画像を保存しようとしたら今回は保存ができず上記のエラーが発生している状態です。
どなたか解決方法が分かりそうな方がおられましたら是非ご教授のほどよろしくお願いします。

回答1件
あなたの回答
tips
プレビュー