uploads to s3

This commit is contained in:
Tyrel Souza 2014-05-29 13:56:37 -04:00
parent f6d957a25c
commit 8aa6b5ac14
3 changed files with 13 additions and 5 deletions

View File

@ -31,6 +31,7 @@ gem 'asset_sync'
gem 'angularjs-rails' gem 'angularjs-rails'
gem 'undertaker' # Thanks Brian gem 'undertaker' # Thanks Brian
gem 'httparty' gem 'httparty'
gem 'aws-sdk'
group :development do group :development do
gem 'foreman' gem 'foreman'

View File

@ -60,6 +60,9 @@ GEM
activemodel activemodel
fog (>= 1.8.0) fog (>= 1.8.0)
awesome_print (1.2.0) awesome_print (1.2.0)
aws-sdk (1.41.0)
json (~> 1.4)
nokogiri (>= 1.4.4)
bcrypt (3.1.7) bcrypt (3.1.7)
better_errors (1.1.0) better_errors (1.1.0)
coderay (>= 1.0.0) coderay (>= 1.0.0)
@ -303,6 +306,7 @@ DEPENDENCIES
annotate! annotate!
asset_sync asset_sync
awesome_print awesome_print
aws-sdk
better_errors better_errors
binding_of_caller binding_of_caller
bootstrap-sass (< 3.1) bootstrap-sass (< 3.1)

View File

@ -3,18 +3,21 @@ require 'tempfile'
class AmazonCopy class AmazonCopy
def download_video videolisting def download_video videolisting
file = Tempfile.new ["video_",".mp4"], "#{Rails.root}/tmp" file = Tempfile.new ["video_",".mp4"], "#{Rails.root}/tmp"
begin begin
file.write HTTParty.get(videolisting.get_video_url).parsed_response.force_encoding("utf-8") file.write HTTParty.get(videolisting.get_video_url).parsed_response.force_encoding("utf-8")
file.flush 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 ensure
file.close file.close
end
file.unlink file.unlink
end
end end
handle_asynchronously :download_video handle_asynchronously :download_video
end end