What is ?
is a cloud services library for Ruby. allows you to seamlessly integrate your cloud configuration into your Ruby application.
Read below to learn how to use with Filebase.
1. Install :
gem install fog
2. Download and install the fog-aws
package:
gem install fog-aws
3. Create the file ~/.fog
with the following content:
Copy 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:
Copy s3 = Fog::Storage.new(provider: 'AWS', region: 'us-east-1', bucket: ‘filebase-bucket’, host: ‘s3.filebase.com’)
Using Fog-AWS
Creating a file:
Copy 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:
Copy directory = s3.directories.get('directory-name', prefix: '/path/to')
directory.files
Generating a Pre-signed URL for a file:
Copy directory.files.new(key: '/path/to/file-name').url(Time.now + 60)
Copying a File to a Bucket
Copy 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:
Copy 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")