Hi. I'm trying to implement shrine into my project and having some problems that I'm hoping you can help me with.
I followed the example for the image uploading from the docs, but I think I missed something. Whenever I try to upload the attachments through the Asset form, the file is uploaded to uploads/cache and the information is saved as such. It was never transferred over to uploads/store. When I upload images using associated uploader (shown below), with versioning, the images seem to processed and stored correctly. For documents, I just want to save the files as is without any processing and it will just saved to cache. Can you tell me what I'm missing? Do I need to add direct_upload plugin?
# app/models/image_uploader.rb
class ImageUploader < Shrine
include ImageProcessing::MiniMagick
plugin :activerecord
plugin :determine_mime_type
plugin :logging, logger: Rails.logger
plugin :remove_attachment
plugin :store_dimensions
plugin :validation_helpers
plugin :versions, names: [:original, :thumb]
Attacher.validate do
validate_max_size 2.megabytes, message: 'is too large (max is 2 MB)'
validate_mime_type_inclusion ['image/jpg', 'image/jpeg', 'image/png', 'image/gif']
end
def process(io, context)
case context[:phase]
when :store
thumb = resize_to_limit!(io.download, 200, 200)
{ original: io, thumb: thumb }
end
end
end
# app/models/document_uploader.rb
class DocumentUploader < Shrine
plugin :validation_helpers
plugin :determine_mime_type
plugin :parallelize
plugin :logging, logger: Rails.logger
plugin :remove_attachment
plugin :delete_raw
Attacher.validate do
validate_max_size 10*1024*1024, message: "is too large (max is 10 MB)"
validate_extension_inclusion [/jpe?g/, "png", "gif", "txt", "pdf", "doc", "docx", "xls", "xlsx"]
validate_mime_type_inclusion ["image/jpeg", "image/png", "image/gif", "application/pdf", "text/plain",
"application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"]
#end
end
def process(io, context)
case context[:phase]
when :store
{ original: io }
end
end
end