vidpush/app/models/amazon_copy.rb

23 lines
628 B
Ruby
Raw Normal View History

require 'httparty'
require 'tempfile'
class AmazonCopy
def download_video videolisting
file = Tempfile.new ["video_",".mp4"], "#{Rails.root}/tmp"
begin
file.write HTTParty.get(videolisting.get_video_url).parsed_response.force_encoding("utf-8")
file.flush
2014-05-29 17:56:37 +00:00
puts "File #{videolisting.videocode} downloaded."
s3 = AWS::S3.new
obj = s3.buckets['digitalmarketingvideos'].objects["#{videolisting.videocode}.mp4"]
obj.write(file)
puts "File #{videolisting.videocode} uploaded."
ensure
file.close
2014-05-29 17:56:37 +00:00
file.unlink
end
end
handle_asynchronously :download_video
end