Module: RailsCom::VideoResponse

Extended by:
ActiveSupport::Concern
Defined in:
lib/rails_com/active_storage/video_response.rb

Instance Method Summary collapse

Instance Method Details

#add_range_headersObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rails_com/active_storage/video_response.rb', line 16

def add_range_headers
  file_size = self.response.body.size
  match = request.headers['range'].to_s.match(/bytes=(\d+)-(\d*)/)
  match = Array(match)
  file_begin = match[1].presence
  file_end = match[2].presence
  if file_begin && file_end
    response.header['Content-Range'] = 'bytes ' + file_begin.to_s + '-' + file_end.to_s + '/' + file_size.to_s
    response.header['Content-Length'] = (file_end.to_i - file_begin.to_i + 1).to_s
    response.status = 206
  end
end

#wrap_videoObject



10
11
12
13
14
# File 'lib/rails_com/active_storage/video_response.rb', line 10

def wrap_video
  if ['video/mp4'].include? self.response.media_type
    add_range_headers
  end
end