Hi!
After save file in file_data column is no derivatives:
{“id”: “1/05/4fc5a8-9fcc-4e4b-95d2-dafafc85a355/images.jpeg”, “storage”: “cache”, “metadata”: {“size”: 6932, “filename”: “images.jpeg”, “mime_type”: “image/jpeg”, “namespace_token”: “054fc5a8-9fcc-4e4b-95d2-dafafc85a355”}}
But activerecord_after_save shows me:
…@record=#<ShrineAttachment id: nil, file: nil, attachable_type: “User”, attachable_id: 2, field_name: “photo”, deleted_at: nil, file_data: {“id”=>“1/6a/386146-443b-4fde-a2c3-aa2cadd02d52/80.png”, “storage”=>“store”, “metadata”=>{“filename”=>“80.png”, “size”=>394, “mime_type”=>“image/png”, “namespace_token”=>“6a386146-443b-4fde-a2c3-aa2cadd02d52”}, “derivatives”=>{“resized_for_list”=>{“id”=>“1/resized_for_list_6a/386146-443b-4fde-a2c3-aa2cadd02d52/image_processing20230411-10-x692k6.png”…
storage: :store and derivatives in file_data…
Can someone explain what happen?
#shrine.rb
require "shrine"
require "shrine/storage/file_system"
Shrine.plugin :activerecord
Shrine.storages = {
store: Shrine::Storage::FileSystem.new("public", prefix: "attachments"),
cache: Shrine::Storage::FileSystem.new("public", prefix: "cache/attachments")
}
class Shrine::Attacher
def promote(*)
create_derivatives
super
end
end
#shrine_attachment_uploader.rb
class ShrineAttachmentUploader < Shrine
plugin ShrinePlugins::TenantLocation
plugin :derivatives, versions_compatibility: true
plugin :add_metadata
# plugin :processing
# plugin :keep_files
# plugin :remove_invalid
# plugin :cached_attachment_data
# plugin :restore_cached_data
plugin :validation_helpers
plugin :validation
plugin :determine_mime_type
Attacher.derivatives do |original|
pipeline = ImageProcessing::MiniMagick.source(original)
resized_for_list = pipeline.resize_to_limit!(400, 300)
resized_for_show = pipeline.resize_to_limit!(800, 600)
{ resized_for_list: resized_for_list, resized_for_show: resized_for_show }
end
def resized_for_show
#derivatives
end
def resized_for_list
#derivatives
end
end