Hello,
i migrating from Carrierwave to Shrine as lightweighting from heavy tight on Rails.
I have central media storage, every file (image, document, video, audio) is stored in one place (model, db, and file system) and then file is associated to another objects.
I don't find any way how to get full file path.
Carrierwave by calling
returns full path as
/Users/Rado/Development/my_app/public/uploads/asset/filename.jpg
but in Shrine it returns only partial path with calling "url" method, because path is not implemented
i could append another partial from storage, but can't get full path.
is there any way how to find full path?
my config and files looks like this:
require 'shrine'
require 'shrine/storage/file_system'
require 'media_info'
Shrine.storages = {
cache: Shrine::Storage::FileSystem.new('public', prefix: 'uploads/cache'),
store: Shrine::Storage::FileSystem.new('public', prefix: 'uploads/asset')
}
Shrine.plugin :activerecord
Shrine.plugin :cached_attachment_data # for forms
class FileUploader < Shrine
plugin :keep_files
plugin :pretty_location
plugin :determine_mime_type,
analyzer: ->(io, analyzers) do
MediaInfo.parse(io.path)&.general&.internet_media_type
end
def generate_location(io, context)
if context[:record]
id = context[:record].id if context[:record].respond_to?(:id)
end
basename = File.basename(context.fetch(:action) == :cache ? super : context.metadata.fetch('filename'))
basename = "#{context[:version]}-#{basename}" if context[:version]
['asset', id, basename].compact.join('/')
end
end