减少多个文件上传时间

时间:2017-09-14 06:55:06

标签: ruby-on-rails amazon-s3 paperclip

我使用输入[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 %>

1 个答案:

答案 0 :(得分:0)