Module: RailsCom::AttachmentTransfer
- Includes:
- ActiveStorage::Downloading
- Defined in:
- lib/rails_com/active_storage/attachment_transfer.rb
Instance Method Summary collapse
Instance Method Details
#copy ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/rails_com/active_storage/attachment_transfer.rb', line 5 def copy raise 'Only Support mirror service' unless service.is_a?(ActiveStorage::Service::MirrorService) download_blob_to_tempfile do |io| checksum = blob.send(:compute_checksum_in_chunks, io) service.mirrors.map do |service| service.upload key, io.tap(&:rewind), checksum: checksum end end end |
#ffmpeg_path ⇒ Object
38 39 40 |
# File 'lib/rails_com/active_storage/attachment_transfer.rb', line 38 def ffmpeg_path ActiveStorage.paths[:ffmpeg] || 'ffmpeg' end |
#transfer_faststart ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rails_com/active_storage/attachment_transfer.rb', line 15 def transfer_faststart attach = self.record.send(self.name) r = nil download_blob_to_tempfile do |input| Tempfile.open([ 'ActiveStorage', self.filename.extension_with_delimiter ], Dir.tmpdir) do |file| file.binmode argv = [ffmpeg_path, '-i', input.path, '-codec', 'copy', '-movflags', 'faststart', '-f', 'mp4', '-y', file.path] system(*argv) file.rewind r = attach.attach io: file, filename: self.filename.to_s, content_type: 'video/mp4' end end self.purge if attach.is_a?(ActiveStorage::Attached::One) r elsif attach.ia_a?(ActiveStorage::Attached::Many) r[0] else r end end |