Fog.io - Ruby
Learn how to configure Fog.io for use with Filebase.

What is Fog.io?

Fog.io is a cloud services library for Ruby. Fog.io allows you to seamlessly integrate your cloud configuration into your Ruby application.
Read below to learn how to use Fog.io with Filebase.

Prerequisites:

  • Have your Filebase Access and Secret Keys. Learn how to view your access keys here.
  • Create a Filebase Bucket. Learn how to create a bucket here.

1. Install Fog.io:

gem install fog

2. Download and install the fog-aws package:

gem install fog-aws

3. Create the file ~/.fog with the following content:

default:
aws_access_key_id: <YOUR_FILEBASE_ACCESS_KEY>
aws_secret_access_key: <YOUR_FILEBASE_SECRET_ACCESS_KEY>

4. In your Ruby application, add fog-aws as a dependency:

require 'fog/aws'

5. Connect to the Filebase S3 service:

s3 = Fog::Storage.new(provider: 'AWS', region: 'us-east-1', bucket: ‘filebase-bucket’, host: ‘s3.filebase.com’)

Using Fog-AWS

Creating a file:

directory = s3.directories.new(key: 'directory-name')
file = directory.files.create(key: '/path/to/file-name, body: File.open('file-name), tags: 'Org-Id=1&Service-Name=My-Service')

Listing files:

directory = s3.directories.get('directory-name', prefix: '/path/to')
directory.files

Generating a Pre-signed URL for a file:

directory.files.new(key: '/path/to/file-name').url(Time.now + 60)

Copying a File to a Bucket

directory = s3.directories.new(key: 'directory-name')
file = directory.files.get('/path/to/file-name')
file.copy("target-bucket", "/path/to/copy-file-location")

Using Multipart Upload

To speed transfers of large files, the concurrency option can be used to spawn multiple threads. Note that the file must be at least 5 MB for multipart uploads to work. For example:
directory = s3.directories.new(key: 'directory-name')
file = directory.files.get('/path/to/file-name')
file.multipart_chunk_size = 10 * 1024 * 1024
file.concurrency = 10
file.copy("target-bucket", "/path/to/copy-file-location")
If you have any questions, please join our Discord server, or send us an email at [email protected]