-
Notifications
You must be signed in to change notification settings - Fork 274
Dynamic S3 Buckets
Janko Marohnić edited this page Nov 13, 2019
·
1 revision
Let's say you want to store files uploaded by users into different S3 buckets,
depending on each user's region. You can define your buckets in
Shrine.storages
and use the default_storage
plugin to
autoconfigure the correct one:
Shrine.storages = {
# ...
store_us: Shrine::Storage::S3.new(bucket: "myapp-files-us", region: "us-east-1", ...)
store_eu: Shrine::Storage::S3.new(bucket: "myapp-files-eu", region: "eu-contral-1", ...)
# ...
}
Shrine.plugin :default_storage
Shrine::Attacher.default_store do
:"store_#{record.user.region}"
end
If the set of possible storage destinations is not bounded, you can use the
dynamic_storage
plugin to dynamically resolve storage
configuration:
Shrine.plugin :dynamic_storage
Shrine.storage /store_(\w+)/ do |match|
Shrine::Storage::S3.new(...)
end