【问题标题】:Reduce multiple file upload time减少多个文件上传时间
【发布时间】:2018-02-23 01:02:35
【问题描述】:

我正在使用 input[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 %>

【问题讨论】:

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


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-10
      • 1970-01-01
      相关资源
      最近更新 更多