Installation
Chunked uploads are a paid feature. Add the commercial gem next to the free one:
gem 'habarico'
gem 'habarico-enterprise'
Then require the module in an initializer — like change history it is opt-in and not loaded by
require "habarico_enterprise", because it registers a process-wide upload finalizer and needs
configuration of its own:
# config/initializers/habarico_uploads.rb
require "habarico_enterprise/uploads"
Requiring it alone changes nothing yet — a field only takes the chunked path once a provider is configured, see Configuration.
The s3 provider needs aws-sdk-s3
aws-sdk-s3 is deliberately not a habarico-enterprise dependency (kept out of the gemspec),
so add it to the host app's Gemfile yourself when using the s3 provider:
gem "aws-sdk-s3"
Without it, Providers::S3#supports_storage? returns false and the field falls back to base64;
calling the upload endpoints directly raises a clear error instead.
Per-field validations need active_storage_validations
initiate enforces the content type and size a field declares (see
Upload validations), but it does not provide a way to
declare them — it reads the ones you already declared with
active_storage_validations on the
file_attr's underlying_attachment. Like aws-sdk-s3, that gem is deliberately not a
habarico-enterprise dependency; add it yourself if you want per-field rules:
gem "active_storage_validations"
class Product < ApplicationRecord
has_one_attached :photo_attachment
file_attr :photo, underlying_attachment: :photo_attachment, nature: :image
validates :photo_attachment,
content_type: %w[image/png image/jpeg],
size: { less_than: 5.megabytes }
end
Without the gem nothing breaks — a field simply declares no rules, and initiate falls back to the
content-type blocklist that always applies.
The gem ships no Czech locale (cs is not among the catalogs it provides), so its own save-time
messages fall back to English in a Czech admin. The initiate-time messages raised by
habarico-enterprise are unaffected — they come from this gem's own catalogs, which cover all 13
supported locales.
Routes
The S3 provider's three endpoints (initiate/complete/abort) are drawn by
Habarico::RoutingService through the same extension hook the schema and search endpoints use, so
the host's config/routes.rb needs no change:
Rails.application.routes.draw do
Habarico::RoutingService.instance.draw_routes
end
They land beside schema at the admin-site root — under routing_url_prefix, and inside the
top-level group when the resources are configured as one ({ admin: [...] }), e.g.
POST /api/admin/uploads/initiate.
The tus provider needs no endpoints of its own — Config::Tus.endpoint just points the frontend
at the external tusd instance directly.
See also
- Installation — the paid gem alongside the free one
- Configuration — threshold, chunk size and provider settings
- Provider selection — choosing between S3 and tus