website logo
Create accountLogin
Home
DCS
Node
Resources
Help center
Navigate through spaces
Home
DCS
Node
Resources
Help center
⌘K
Storj DCS
Get Started
AWS CLI and Hosted Gateway MT
AWS SDK and Hosted Gateway MT
Uplink CLI
Satellite Admin Console
Object Browser
Downloads
Download Uplink CLI
Download Self-hosted S3 Compatible Gateway
Download Storj Client Libraries
SDKs & Reference
Tutorial
How-to Guides
Concepts
Support
Support Overview
FAQ
Community Forum
Status Page
Help Desk
Billing, Payment & Accounts
Resources
Moved Documents
Docs powered by archbee 
17min

Rails Active Storage

This guide will show you how to connect ActiveStorage in Rails 7 to Storj (an AWS S3 compatible object storage). You can also look at the source code of this example. We have a webinar walking you through it, but you can also refer to the steps below:



Prerequisites:

  • Installed ruby 3.1.2 or later
  • Installed rails 7.0.4.2 or later
  • Storj S3 compatiable access and secret key (see AWS SDK and Hosted Gateway MT)
  • A bucket created on Storj (see Create a Bucket)

Configure ActiveStorage to Storj

Create a new rails app

Shell
|


Install ActiveStorage

Shell
|


Edit Gemfile, add the aws-sdk-s3 gem and run bundle install

Ruby
|


Edit the rails credentials

Shell
|


Add to the credentials your access key and secret key (see AWS SDK and Hosted Gateway MT) under storj:

YAML
|


Edit config/storage.yml, enter the following to configure ActiveStorage to use Storj. Be sure to replace the bucket with the one created earlier (see Create a Bucket)

YAML
|


Edit config/environments/development.rb, change the ActiveStorage service to :storj

Ruby
|


Use active storage images hosted by Storj

First we'll need a basic app to interact with generated with Rails scaffolding

Shell
|


Edit config/routes.rb set root to "names#index

Ruby
|


Edit app/models/name.rb to have has_one_attached

Ruby
|


Edit app/views/names/_form.html.erb to include a field_field to allow the user to choose a file to upload

erb
|


Navigate to http://localhost:3000/names/new and you should see the following



Click "Create Name" Edit app/views/names/show.html.erb to include <%= image_tag @name.main_image %> to display the image

erb
|


Edit app/assets/stylesheets/application.css to style the image to fix the size of the screen

CSS
|


Navigate to http://localhost:3000/names/1 to see your image

Enable direct to Storj upload

Edit config/importmap.rb to include the @rails/activestorage package

Ruby
|


Edit app/javascript/controllers/application.js to initialize the ActiveStorage

JS
|


Modify app/views/names/_form.html.erb form.file_field to include direct_upload: true

erb
|






Updated 28 Feb 2023
Did this page help you?
Yes
No
UP NEXT
Presigned URLs in the serverless cloud
Docs powered by archbee 
TABLE OF CONTENTS
Prerequisites:
Configure ActiveStorage to Storj
Use active storage images hosted by Storj
Enable direct to Storj upload