I managed to upload files to s3 using shrine, but I'm trying to upload each photo to a different folder according to the album it belongs to.
Lets say i have a bucket named: abc
:
Uploading images to the album: family
should upload images to: abc/family/...
Uploading images to the album: friends
should upload images to: abc/friends/...
I didn't find a way to do it in Shrine.storages
in the initializer file.
I guess the way to do it is with default_storage
and dynamic_storage
plugins somehow, but i didn't succeed doing it yet.
any suggestions / solution?
Thanks a lot :)
Relations:
Album has_many :photos
Photo belongs_to :album
Photo
class has image_data
field for Shrine.
my code in the initializer: (basic stuff)
s3_options = {
access_key_id: ENV["S3_KEY"],
secret_access_key: ENV["S3_SECRET"],
region: ENV["S3_REGION"],
bucket: ENV["S3_BUCKET"],
}
Shrine.storages = {
cache: Shrine::Storage::S3.new(prefix: "cache", **s3_options),
store: Shrine::Storage::S3.new(prefix: "store", **s3_options),
}
EDIT:
I found out there is a plugin named: pretty_location
which adds a nicer folder structure, but its not exactly what i need, it adds /Photo/:photo_id/image/:image_name
under the bucket, but i need the album name instead.