Hi
do we should use direct image upload with background job in same time or we can use just direct image upload ?
in shrine.rb in configuration i wrote
require "shrine"
require "shrine/storage/file_system"
require "image_processing/mini_magick"
Shrine.storages = {
cache: Shrine::Storage::FileSystem.new("public", prefix: "images/cache"),
store: Shrine::Storage::FileSystem.new("public", prefix: "images/store"),
}
Shrine.plugin :activerecord
Shrine.plugin :logging, logger: Rails.logger
Shrine.plugin :cached_attachment_data
Shrine.plugin :direct_upload
Shrine.plugin :backgrounding
Shrine.plugin :rack_file
i create a image_uploader.rb model and look like this :
require "image_processing/mini_magick"
class ImageUploader < Shrine
include ImageProcessing::MiniMagick
plugin :determine_mime_type
plugin :remove_attachment
plugin :cached_attachment_data
plugin :store_dimensions
plugin :validation_helpers
plugin :pretty_location
plugin :processing
plugin :versions
plugin :backgrounding
plugin :direct_upload
Attacher.validate do
validate_max_size 1.megabytes, message: 'ماکزیمم سایز آپلود ۱ مگابایت است.'
validate_mime_type_inclusion ['image/jpeg', 'image/png', 'image/gif']
end
process(:store) do |io|
thumb = resize_to_limit!(io.download, 160, 95)
small = resize_to_limit!(io.download, 320, 190)
big = resize_to_limit!(io.download, 640, 360)
{ original: io, thumb: thumb, small: small, big: big}
end
end
i have a class like product , i generate it with scaffold and it is very routine. in the _form.html.erb in part of upload is like this:
<fieldset>
<div class="field">
<%= f.file_field :mainpic %>
<%- if @internet_bon.mainpic_data? %>
<div class="field">
<%= image_tag @internet_bon.mainpic_url(:small) %>
</div>
<%= f.hidden_field :image, value: internet_bon.cached_mainpic_data %>
<%- end %>
= </div>
<fieldset>
i want when user select file , file upload and shown in form (in edit and new action). but seems direct upload plugin don't work .
i attach jquery-file-upload in application.js but nothing happed
another thing that i want to crop image after shown in form.
you create a wonderful gem, why not create a rails 5 sample with jqury-file-upload and cropping ability, most of web app need this ability ! your sample have not routine _form.html.erb
many tanks