0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CarrierWaveの保存先をS3からローカルに戻す方法。

Last updated at Posted at 2019-02-20

#両方とも Fileにする

config/initializers/carruerwave.rb
CarrierWave.configure do |config|
  if Rails.env.production?
    config.storage :file
  # config.fog_credentials = {
  #     :provider               => 'AWS',
  #     :aws_access_key_id      => ENV['UPLOAD_APIKEY'],
  #     :aws_secret_access_key  => ENV['UPLOAD_SECRETKEY'],
  #     :region                 => 'ap-northeast-1'
  # }
  #
  # config.fog_directory = ENV['UPLOAD_BUCKET']
  else
    config.storage :file
  end

end

AWS S3の表記をコメントアウトして 両方ともFileにする。

#Uploaderのファイルを編集

app/uploaders/ckeditor_wave/ck_image_uploader.rb
  class CkImageUploader < CarrierWave::Uploader::Base

    # Include RMagick or ImageScience support:
    # include CarrierWave::RMagick
    include CarrierWave::MiniMagick
    # include CarrierWave::ImageScience

    # Choose what kind of storage to use for this uploader:
    if Rails.env.production? || Rails.env.staging?
      # storage :fog
      storage :file
    else
      storage :file
    end

こちらも両方ともFileにする。

#Herokuから ENVKEYを削除する

$ heroku config:unset UPLOAD_BUCKET
$ heroku config:unset UPLOAD_SECRETKEY
$ heroku config:unset UPLOAD_APIKEY

これでS3 への接続が削除される。

#補足
このままでも運用できるが、Herokuはローカルに保存すると
毎日アップロードしたデータ・画像は削除される。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?