Skip to content

Configure Scaleway S3 for Active Storage in Rails 6.0

Posted on:March 26, 2021

Scaleway is a French web hosting company, founded by Xavier Niel in 1999. It provides physical and online dedicated servers, domain registration services and datacenters.

In 2020, Scaleway was the second player in France behind OVHCloud and the third in Europe.

If you want an alternative to Amazon AWS S3 storage services that we use @Kinoba, follow along this tiny and easy tutorial 😊

Scaleway part

Let’s begin with the Scaleway config 👨🏻‍🔧

Here, a help procedure if needed: 👉🏻 https://www.scaleway.com/en/docs/object-storage-feature/#-Operation-Procedures

👉🏻 https://www.scaleway.com/en/docs/generate-api-keys/

Ruby On Rails part

The funniest part: integrating Scaleway into your Rails app 👩🏽‍💻

# Gemfile
gem 'aws-sdk-s3', require: false
# .env
SCALEWAY_ACCESS_KEY_ID=YOUR_ACCESS_KEY_ID
SCALEWAY_SECRET_ACCESS_KEY_ID=YOUR_SECRET_ACCESS_KEY_ID
SCALEWAY_BUCKET_NAME=YOUR_BUCKET_NAME
# storage.yml
test:
  service: Disk
  root: <%= Rails.root.join("tmp/storage") %>

local:
  service: Disk
  root: <%= Rails.root.join("storage") %>

scaleway:
  service: S3
  endpoint: https://s3.fr-par.scw.cloud # Scaleway API endpoint, depending on your region
  access_key_id: <%= ENV['SCALEWAY_ACCESS_KEY_ID'] %> # Do not forget to hide your secrets
  secret_access_key: <%= ENV['SCALEWAY_SECRET_ACCESS_KEY_ID'] %> # Do not forget to hide your secrets
  region: fr-par # Your bucket region, here it's Paris
  bucket: <%= ENV['SCALEWAY_BUCKET_NAME'] %> # Your bucket name
# production.rb
config.active_storage.service = :scaleway
# user.rb
has_one_attached :avatar
# users_controller.rb
@user.avatar.attach(params[:avatar])

That’s it 🎉

easy peasy gif