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

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

新規登録して質問してみよう
ただいま回答率
85.48%
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)とはアマゾン・ウェブ・サービスが提供するオンラインストレージサービスです。

Q&A

1回答

1382閲覧

Herokuで公開したinstagram cloneアプリ投稿画像が時間が経つと消える問題を解決すためにAWSのS3を使いたい

kim.soonhyang

総合スコア14

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)とはアマゾン・ウェブ・サービスが提供するオンラインストレージサービスです。

0グッド

0クリップ

投稿2020/04/14 05:50

instagram cloneを無事に完成させました!(教材をみながらですが、、)
充実感や嬉しさを感じつつ次の学習に取り込もうとしている最中でした。
herokuを利用してアプリを公開しましたが、一定時間が経つと、投稿している画像が消えるので調べてみました。
Heroku上のリポジトリ (Dyno) が最後のコミットの状態にリセットされるから(destroy状態になるという意味でしょうか)だそうです。

表題のようにAWS/S3のストレージサービスを使って問題を解決したいですがApplication errorになってしまい中身をみれない状態になってしまいました、、
以下のような設定をしましたが、何が足りないのか、間違っているのか、教えていただけないでしょうか。
よろしくお願いいたします。

□AWS/S3で設定したこと
IAMユーザー登録 → バケットを作成する → アクセスキー ID&シークレットアクセスキー取得

□プロジェクトファイルを編集

gemfile

1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '2.6.3' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 7gem 'rails', '~> 5.2.3' 8# Use sqlite3 as the database for Active Record 9gem 'sqlite3', '~>1.3.6', group: :development 10# Use Puma as the app server 11gem 'puma', '~> 3.11' 12# Use SCSS for stylesheets 13gem 'sass-rails', '~> 5.0' 14# Use Uglifier as compressor for JavaScript assets 15gem 'uglifier', '>= 1.3.0' 16# See https://github.com/rails/execjs#readme for more supported runtimes 17# gem 'mini_racer', platforms: :ruby 18 19# Use CoffeeScript for .coffee assets and views 20gem 'coffee-rails', '~> 4.2' 21# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 22gem 'turbolinks', '~> 5' 23# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 24gem 'jbuilder', '~> 2.5' 25# Use Redis adapter to run Action Cable in production 26# gem 'redis', '~> 4.0' 27# Use ActiveModel has_secure_password 28# gem 'bcrypt', '~> 3.1.7' 29 30# Use ActiveStorage variant 31# gem 'mini_magick', '~> 4.8' 32 33# Use Capistrano for deployment 34# gem 'capistrano-rails', group: :development 35 36# Reduces boot times through caching; required in config/boot.rb 37gem 'bootsnap', '>= 1.1.0', require: false 38 39group :development, :test do 40 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 41 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 42end 43 44group :development do 45 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 46 gem 'web-console', '>= 3.3.0' 47 gem 'listen', '>= 3.0.5', '< 3.2' 48 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 49 gem 'spring' 50 gem 'spring-watcher-listen', '~> 2.0.0' 51end 52 53group :test do 54 # Adds support for Capybara system testing and selenium driver 55 gem 'capybara', '>= 2.15' 56 gem 'selenium-webdriver' 57 # Easy installation and use of chromedriver to run system tests with Chrome 58 gem 'chromedriver-helper' 59end 60 61# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 62gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 63 64gem 'bootstrap', '~> 4.4.1' 65gem 'jquery-rails' 66gem 'devise', '~> 4.6.1' 67gem 'carrierwave', '~> 1.0' 68gem 'rmagick', require: 'RMagick' 69gem 'pg', group: :production 70gem 'fog-aws' 71gem 'aws-sdk', '~> 3.0', '>= 3.0.1' 72gem 'simple_form' 73

rb

1config/environments/production.rb 2# Enable serving of images, stylesheets, and JavaScripts from an asset server. 3 # config.action_controller.asset_host = 'http://assets.example.com' 4 5 # Specifies the header that your server uses for sending files. 6 # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 7 # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 8 9 # Store uploaded files on the local file system (see config/storage.yml for options) 10 config.active_storage.service = :amazon 11 12 # Mount Action Cable outside main process or domain 13 # config.action_cable.mount_path = nil 14 # config.action_cable.url = 'wss://example.com/cable' 15 # config.action_cable.allowed_request_origins = [ 'http://example.com', /http://example.*/ ] 16 17 # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 18 # config.force_ssl = true 19 20 # Use the lowest log level to ensure availability of diagnostic information 21 # when problems arise. 22 config.log_level = :debug 23 24 # Prepend all log lines with the following tags. 25 config.log_tags = [ :request_id ] 26 27 # Use a different cache store in production. 28 # config.cache_store = :mem_cache_store 29 30 # Use a real queuing backend for Active Job (and separate queues per environment) 31 # config.active_job.queue_adapter = :resque 32 # config.active_job.queue_name_prefix = "techpitgram_#{Rails.env}" 33 34 config.action_mailer.perform_caching = false 35 36 # Ignore bad email addresses and do not raise email delivery errors. 37 # Set this to true and configure the email server for immediate delivery to raise delivery errors. 38 # config.action_mailer.raise_delivery_errors = false 39 40 # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 41 # the I18n.default_locale when a translation cannot be found). 42 config.i18n.fallbacks = true 43 44 # Send deprecation notices to registered listeners. 45 config.active_support.deprecation = :notify 46 47 # Use default logging formatter so that PID and timestamp are not suppressed. 48 config.log_formatter = ::Logger::Formatter.new 49 50 # Use a different logger for distributed setups. 51 # require 'syslog/logger' 52 # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 53 54 if ENV["RAILS_LOG_TO_STDOUT"].present? 55 logger = ActiveSupport::Logger.new(STDOUT) 56 logger.formatter = config.log_formatter 57 config.logger = ActiveSupport::TaggedLogging.new(logger) 58 end 59 60 # Do not dump schema after migrations. 61 config.active_record.dump_schema_after_migration = false 62end

yml

1config/storage.yml 2 3test: 4 service: Disk 5 root: <%= Rails.root.join("tmp/storage") %> 6 7local: 8 service: Disk 9 root: <%= Rails.root.join("storage") %> 10 11# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 12 amazon: 13 service: S3 14 access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 15 secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 16 region: ap-northeast-1 17 bucket: croasgram-photo-123 18 19# Remember not to checkin your GCS keyfile to a repository 20# google: 21# service: GCS 22# project: your_project 23# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 24# bucket: your_own_bucket 25 26# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 27# microsoft: 28# service: AzureStorage 29# storage_account_name: your_account_name 30# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 31# container: your_container_name 32 33# mirror: 34# service: Mirror 35# primary: local 36# mirrors: [ amazon, google, microsoft ] 37

heroku logs

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

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

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

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

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

guest

回答1

0

一旦削除してやり直して見たいと思います。
原因が解ればまた投稿させていただきます。

投稿2020/04/15 08:04

kim.soonhyang

総合スコア14

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問