[RUBY] [Rails] How to upload images to AWS S3 using refile and refile-s3

Target

ezgif.com-video-to-gif.gif

Development environment

・ Ruby: 2.5.7 Rails: 5.2.4 ・ Vagrant: 2.2.7 -VirtualBox: 6.1 ・ OS: macOS Catalina

Premise

Perform up to "making keys into environment variables" in ʻAWS settings and implementation` in the following article.

How to upload images to AWS S3 using Carrierwave and fog-aws

Implementation

Create / edit refile.rb

Terminal


$ touch config/initializers/refile.rb

refile.rb


require 'refile/s3'

if Rails.env.production? #Upload to S3 in production environment
  aws = {
    access_key_id: ENV['S3_ACCESS_KEY_ID'], #Access key ID
    secret_access_key: ENV['S3_SECRET_ACCESS_KEY'], #Secret access key
    region: 'ap-northeast-1', #region
    bucket: 'matsubishi-sample', #Bucket name
  }
  Refile.cache = Refile::S3.new(prefix: 'cache', **aws)
  Refile.store = Refile::S3.new(prefix: 'store', **aws)
end

Recommended Posts

[Rails] How to upload images to AWS S3 using refile and refile-s3
[Rails] How to upload images to AWS S3 using Carrierwave and fog-aws
[Rails] How to upload multiple images using Carrierwave
upload images to refile heroku S3
How to save images on Heroku to S3 on AWS
How to deploy to AWS using NUXTJS official S3 and CloudFront? With docker-compose
[rails] How to post images
[Rails API + Vue] Upload and display images using Active Storage
How to set and describe environment variables using Rails zsh
[Rails] How to delete images uploaded by carrierwave (using devise)
[rails6.0.0] How to save images using Active Storage in wizard format
Upload Rails app image file to S3
How to implement image posting using rails
[Rails] How to handle data using enum
[Android] How to pass images and receive callbacks when sharing using ShareCompat
How to output Excel and PDF using Excella
How to execute and mock methods using JUnit
[Rails] How to create a graph using lazy_high_charts
How to output CSV created by Rails to S3
How to play audio and music using javascript
How to link images using FactoryBot Active Storage
[Rails] How to get success and error messages
[Ruby on Rails] Upload multiple images with refile
Rails scope anti-patterns and how to eliminate them
How to post images on Heroku + CarrierWave + S3
How to write Rails
How to uninstall Rails
How to convert A to a and a to A using AND and OR in Java
[Rails] How to edit and customize devise view and controller
[Rails] Create sitemap using sitemap_generator and deploy to GAE
[Rails 6] Add images to seed files (using Active Storage)
Rails learning How to implement search function using ActiveModel
(Ruby on Rails6) How to create models and tables
How to implement a circular profile image in Rails using CarrierWave and R Magick
[Rails] How to install a decorator using gem draper
Try to implement tagging function using rails and js
How to input multiple images at once using rake task
Prevent operations! How to securely update Rails manually using transactions
[Rails] Differences between redirect_to and render methods and how to output render methods
How to deploy jQuery in your Rails app using Webpacker
How to join a table without using DBFlute and sql
How to run React and Rails on the same server
[Rails] I tried to implement "Like function" using rails and js
[AWS / S3] After all, how do you upload multiple files?
How to deploy a Rails application on AWS (article summary)
[AWS] How to check logs
How to handle uploaded images
[Rails] Save images using carrierwave
[Rails] How to use enum
[Rails] How to install devise
How to minimize Java images
[Rails] How to use enum
How to read rails routes
How to terminate rails server
How to write Rails validation
How to write Rails seed
[Rails] How to use validation
[Rails] How to disable turbolinks
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[Rails] How to implement scraping