質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Amazon S3

Amazon S3 (Simple Storage Service)とはアマゾン・ウェブ・サービスが提供するオンラインストレージサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

1回答

1938閲覧

AWS S3を使用しHerokuにデプロイしたが、画像の投稿ができない

kousuke24

総合スコア29

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Amazon S3

Amazon S3 (Simple Storage Service)とはアマゾン・ウェブ・サービスが提供するオンラインストレージサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2019/10/03 03:02

現在Ruby on Railsで画像を投稿するサイトを作成しており、Herokuでデプロイしました。画像のアップロードにはcarrierwaveを使用し、保存先としてAWS S3を設定しています。開発環境では画像の投稿、削除、プロフィール画像の変更等は問題なくできるのですが、本番環境だとこれら全てができなくなっています。

該当コード

imag_uploader.rb

class ImageUploader < CarrierWave::Uploader::Base # Include RMagick or MiniMagick support: # include CarrierWave::RMagick include CarrierWave::MiniMagick if Rails.env.development? strage :file elsif Rails.env.test? storage :file else storage :fog end # 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 # Provide a default URL as a default if there hasn't been a file uploaded: # def default_url(*args) # # For Rails 3.1+ asset pipeline compatibility: # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) # # "/images/fallback/" + [version_name, "default.png"].compact.join('_') # end # Process files as they are uploaded: # process scale: [200, 300] # # def scale(width, height) # # do something # end # Create different versions of your uploaded files: # version :thumb do # process resize_to_fit: [50, 50] # end version :medium do process resize_to_fill: [325, 225] end version :thumb do process resize_to_fit: [150, 150] end # Add a white list of extensions which are allowed to be uploaded. # For images you might use something like this: def extension_whitelist %w(jpg jpeg gif png) end # Override the filename of the uploaded files: # Avoid using model.id or version_name here, see uploader/store.rb for details. # def filename # "something.jpg" if original_filename # end end

carrierwave.rb

require 'carrierwave/storage/abstract' require 'carrierwave/storage/file' require 'carrierwave/storage/fog' if Rails.env.production? CarrierWave.configure do |config| config.storage :fog config.fog_provider = 'fog/aws' config.fog_directory = 'nekojita' config.fog_credentials = { provider: 'AWS', aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'], aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], region: ENV['AWS_DEFAULT_REGION'], path_style: true } end end

git push heroku master

中略 remote: [1/4] Resolving packages... remote: [2/4] Fetching packages... remote: info fsevents@1.2.9: The platform "linux" is incompatible with this mo dule. remote: info "fsevents@1.2.9" is an optional dependency and failed compatibili ty check. Excluding it from installation. remote: [3/4] Linking dependencies... remote: warning " > webpack-dev-server@3.8.1" has unmet peer dependency "webpa ck@^4.0.0". remote: warning "webpack-dev-server > webpack-dev-middleware@3.7.1" has unmet peer dependency "webpack@^4.0.0". remote: [4/4] Building fresh packages... remote: Done in 20.95s. remote: Compiling… remote: Compiled all packs in /tmp/build_aac9acab0414ea445452535543160c24/publ ic/packs remote: Asset precompilation completed (31.94s) remote: Cleaning assets remote: Running: rake assets:clean remote: -----> Detecting rails configuration remote: remote: ###### WARNING: remote: remote: You set your `config.assets.compile = true` in production. remote: This can negatively impact the performance of your application. remote: remote: For more information can be found in this article: remote: https://devcenter.heroku.com/articles/rails-asset-pipeline#compile-s et-to-true-in-production remote: remote: remote: ###### WARNING: remote: remote: You set your `config.active_storage.service` to :local in production. remote: If you are uploading files to this app, they will not persist after th e app remote: is restarted, on one-off dynos, or if the app has multiple dynos. remote: Heroku applications have an ephemeral file system. To remote: persist uploaded files, please use a service such as S3 and update you r Rails remote: configuration. remote: remote: For more information can be found in this article: remote: https://devcenter.heroku.com/articles/active-storage-on-heroku remote: remote: remote: ###### WARNING: remote: remote: We detected that some binary dependencies required to remote: use all the preview features of Active Storage are not remote: present on this system. remote: remote: For more information please see: remote: https://devcenter.heroku.com/articles/active-storage-on-heroku remote: remote: remote: ###### WARNING: remote: remote: No Procfile detected, using the default web server. remote: We recommend explicitly declaring how to boot your server process via a Procfile. remote: https://devcenter.heroku.com/articles/ruby-default-web-server remote: remote: remote: -----> Discovering process types remote: Procfile declares types -> (none) remote: Default types for buildpack -> console, rake, web remote: remote: -----> Compressing... remote: Done: 97.3M remote: -----> Launching... remote: Released v18 remote: https://nekonosita.herokuapp.com/ deployed to Heroku remote: remote: Verifying deploy... done. To https://git.heroku.com/nekonosita.git 25f867c..f611c1d master -> master

その他

アクセスキー、シークレットキー等は.envに記述しています。

かなり抽象的な質問になってしまっていますが、ご教授頂ければ幸いです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

AWSのアクセスキー、シークレットキーを新しいものに変更したところ解決しました。
画像が投稿できなかった原因は、アクセスキーだけを更新していて両者が一致していなかったことが原因と思われる。

投稿2019/10/03 06:50

kousuke24

総合スコア29

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問