How to integrate Object Storage with Ruby?

How to integrate Object Storage with Ruby?

Certainly! Here are detailed steps for setting up and using Minio Cluster on AccuWeb.Cloud, integrating it with a Java project, and managing file uploads:

Step-by-Step Guide

Login to AccuWeb.Cloud Dashboard

  • Navigate to AccuWeb.Cloud: Open your web browser and go to AccuWeb.Cloud.
  • Login: Enter your credentials (username and password) to access your AccuWeb.Cloud dashboard.

Install Minio Cluster from the Marketplace

Step 3. Go to Marketplace: Locate and click on “Marketplace” in your AccuWeb.Cloud dashboard.

Step 4. Search and Install Minio Cluster: In the Marketplace, navigate to “Storage & File” and search for Minio Cluster. Install it following the prompts.

Storage and File

Configure Minio Cluster

Configure Minio Cluster: After installation, configure your Minio Cluster by specifying:

  • Number of nodes (e.g., 1 node for demo purposes)
  • Environment name (e.g., minio-cluster-demo)
  • Display name (e.g., Minio Cluster Demo)
  • Region (e.g., US)

Install MinIO Cluster

Retrieve Minio Cluster Credentials

Check Email: Check your registered email for the Minio Cluster admin panel URL, Access Key, and Secret Key provided after installation.

Cluster Admin Credentials

Log in to Minio Cluster

Access Minio Cluster: Using the credentials received, login to the Minio Cluster admin panel.

Access Cluster

Create a Bucket

Create Bucket: Within the Minio Cluster admin panel, create a new bucket for storing files.

Create a Bucket

Access File Storage in Bucket

Upload and View Files: Upload files to your created bucket. Verify successful upload by checking the file list within the bucket.

Upload and View Files

Configure minIO in the ruby application

Integrating MinIO with a Ruby application involves using the aws-sdk-s3 gem, which provides a comprehensive interface to interact with Amazon S3 and compatible services like MinIO.

Here’s a step-by-step guide to integrate MinIO with your Ruby application:

Step 1. Install the aws-sdk-s3 Gem

Add the aws-sdk-s3 gem to your Gemfile:


gem 'aws-sdk-s3'

Run bundle install to install the gem.

Step 2. Environment Variables

It’s good practice to store your credentials and endpoint in environment variables for security reasons. You can set them in your .env file if you’re using a gem like dotenv-rails.
Create a .env file in your project root:


MINIO_ENDPOINT=http://your-minio-endpoint
MINIO_ACCESS_KEY=your-access-key
MINIO_SECRET_KEY=your-secret-key

Step 3. Configure MinIO Credentials

MinIO uses the same credential structure as AWS S3. Create a configuration file (config/initializers/minio.rb) to set up the connection to MinIO.


require 'aws-sdk-s3'
Aws.config.update({
endpoint: ENV['MINIO_ENDPOINT'],
access_key_id: ENV['MINIO_ACCESS_KEY'],
secret_access_key: ENV['MINIO_SECRET_KEY'],
region: 'us-east-1',
force_path_style: true
})

Step 4. create the controller and put the following code


def create
@upload = Upload.new(upload_params)
puts "New Upload Object:"
puts @upload.inspect
if @upload.save
uploaded_file = params[:upload][:filename]
filename = uploaded_file.original_filename
# Upload file to MinIO
obj = S3_BUCKET.object(filename)
obj.upload_file(uploaded_file.tempfile, acl: 'public-read') # Adjust ACL as per your needs
# File.open(Rails.root.join('public', 'uploads', uploaded_file.original_filename), 'wb') do |file|
#  file.write(uploaded_file.read)
#end
redirect_to @upload, notice: 'File was successfully uploaded.'
else
render :new
end
end
private
def upload_params
params.require(:upload).permit(:filename, :filesize)
end