2017-09-14 70 views
0

我上传了多个图像和视频,输入[type ='file'], 上传需要很长时间。 有什么办法可以缩短上传时间吗? 这里是我当前的代码:减少多个文件上传时间

回形针设置

 has_attached_file :file, styles: lambda { |a| a.instance.check_file_type} 
    validates_attachment_content_type :file, content_type: [/\Aimage\/.*\Z/,/\Avideo\/.*\Z/] 

    def is_video? 
    file.content_type =~ %r(video) 
    end 

    def is_image? 
    file.content_type =~ %r(image) 
    end 

    def check_file_type 
    if is_image? 
     { :medium => { :geometry => "640x480" }, 
     :thumb => { :geometry => "100x100#" } } 
    elsif is_video? 
     { :medium => { :geometry => "640x480", :format => 'mp4', :processors => [:transcoder] }, 
     :thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10 }} 
    else 
     {} 
    end 
    end 

_form.html.erb

<%= simple_form_for(@room, remote: true, format: :js, authenticity_token: true, html: {multipart: true}) do |f| %> 
    *******other fields*********** 
    <input id="video-selector" type="file" name="files[]" accept="video/*,image/*" capture="camcorder" hidden="true" class="hide" multiple 
        onchange="$('#upload-file-info').addClass('label-info').append(this.files[0].name);"> 
<% end %> 

回答