direct image upload and then crop

286 views
Skip to first unread message

arman...@gmail.com

unread,
Jan 1, 2017, 1:08:50 PM1/1/17
to Shrine
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








Janko Marohnić

unread,
Jan 1, 2017, 8:51:42 PM1/1/17
to arman...@gmail.com, Shrine
do we should use direct image upload with background job in same time or we can use just direct image upload ?

Yes, of course, these two features are meant to be additive. Direct upload is just another way to cache the file (alternative to submitting the file with the rest of the form), and Shrine always promotes the cached file to permanent storage, which is the part that typically handles processing and can be backgrounded.

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

Simply adding jquery-file-upload to your application.js won't magically make the uploads asynchronous. Shrine is just a Ruby library, which means that you still have to write all the JavaScript that you want. If you take into consideration that direct uploads can be done with jQuery-File-Upload/Dropzone/FineUploader/Other, and that you can have single or multiple file uploads either to your app or directly to S3, it wouldn't make sense for Shrine to ship with JavaScript which tries to do anything automagically, simply because there are so many ways that direct uploads can be done.

another thing that i want to crop image after shown in form.

If you look at the image_processing gem (which is mentioned in the Shrine README), you'll notice that it does have a method cropping images (#crop). See this answer for a way how you can implement cropping with Shrine and direct uploads; this example is for when you display the cropping UI (e.g. using Jcrop) after the file was directly uploaded, but before it is submitted to the app.

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

The community has created a Rails example app, and it is linked on the Shrine website ;). I don't think that cropping is needed by most applications, and since the app already features multiple direct S3 uploads with background processing, I think that also adding cropping on top of all that would be a bit too much for an "example app".

Kind regards,
Janko

--
You received this message because you are subscribed to the Google Groups "Shrine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-shrine+unsubscribe@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-shrine/05d58241-3972-47eb-9087-bf9f6fdf4c45%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

arman...@gmail.com

unread,
Jan 2, 2017, 1:23:05 AM1/2/17
to Shrine
Dear Janko

I see example app before and ass i explain i think you should create example app with simple scaffolding with one _form and two method on it.
for example what this line should be if we have edit like  product/10/edit

$.ajax("/album/photos", {method: 'POST', data: {photo: {image: JSON.stringify(image)}}})

----

dos driect upload without javascript?


tanks

Janko Marohnić

unread,
Jan 2, 2017, 6:24:45 AM1/2/17
to Arman Emadi, Shrine
Answered here.

--
You received this message because you are subscribed to the Google Groups "Shrine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-shrine+unsubscribe@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages