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 %>