Why use a hosted file service from Rails
Your Rails app can keep files on its own disk, or in a bucket it has to configure, secure and resize for. With Fileboy the app sends the file once, gets an ID back and keeps only that ID. Images are resized by changing a URL, so there is no image processing in your app, and the same ID works from any language.
1. Install the package
bundle add fileboyYou need a public key. Create a free app and copy it from the Keys page. Keep keys out of your code: read them from credentials or the environment.
2. Configure it once
Fileboy.configure do |config|
config.public_key = Rails.application.credentials.dig(:fileboy, :public_key)
config.private_key = Rails.application.credentials.dig(:fileboy, :private_key) # optional
end3. Upload and keep the ID
Pass the uploaded file through. The call returns the file's details, and the id is the only thing to store.
class AvatarsController < ApplicationController
def create
upload = params.require(:avatar) # ActionDispatch::Http::UploadedFile
file = Fileboy.client.upload_file(
upload.tempfile,
name: upload.original_filename,
mime: upload.content_type
)
current_user.update!(avatar_fileboy_id: file.id)
redirect_to profile_path
rescue Fileboy::Error => e
redirect_to profile_path, alert: "Upload failed: #{e.message}"
end
endclass AddAvatarFileboyIdToUsers < ActiveRecord::Migration[7.1]
def change
add_column :users, :avatar_fileboy_id, :string
end
end4. Show the image at the size you need
Build the URL from the stored ID. Asking for the size you display keeps pages light, and the original is never changed.
module AvatarHelper
def avatar_url(user, size: 96)
return unless user.avatar_fileboy_id
Fileboy.client.build_image_url(user.avatar_fileboy_id, transforms: [
{ type: :resize, width: size * 2, height: size * 2, fit: :cover },
{ type: :format, format: :webp }
])
end
endReading a file or image needs no key, so these URLs work in <img> tags, emails and anywhere else, unless the app requires signed URLs. Uploads are what your key authorises.
Checked against the current libraries in November 2026. Found something that no longer works? Tell us.