diff --git a/Gemfile b/Gemfile index 8cdb31e..dd12399 100644 --- a/Gemfile +++ b/Gemfile @@ -31,6 +31,7 @@ gem 'asset_sync' gem 'angularjs-rails' gem 'undertaker' # Thanks Brian gem 'httparty' +gem 'aws-sdk' group :development do gem 'foreman' diff --git a/Gemfile.lock b/Gemfile.lock index c93f421..5e259f2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -60,6 +60,9 @@ GEM activemodel fog (>= 1.8.0) awesome_print (1.2.0) + aws-sdk (1.41.0) + json (~> 1.4) + nokogiri (>= 1.4.4) bcrypt (3.1.7) better_errors (1.1.0) coderay (>= 1.0.0) @@ -303,6 +306,7 @@ DEPENDENCIES annotate! asset_sync awesome_print + aws-sdk better_errors binding_of_caller bootstrap-sass (< 3.1) diff --git a/app/models/amazon_copy.rb b/app/models/amazon_copy.rb index c30b18d..0e922ce 100644 --- a/app/models/amazon_copy.rb +++ b/app/models/amazon_copy.rb @@ -3,18 +3,21 @@ 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 + 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 + file.unlink end - - - file.unlink - end handle_asynchronously :download_video end \ No newline at end of file