added a task to upload

This commit is contained in:
zhitomirskiyi 2011-01-11 17:36:45 -08:00
parent 7477a22421
commit 0f9dc4954a
2 changed files with 21 additions and 4 deletions

View file

@ -3,11 +3,11 @@
# the COPYRIGHT file.
CarrierWave.configure do |config|
if APP_CONFIG[:s3_key] && APP_CONFIG[:s3_secret] && APP_CONFIG[:s3_bucket]
if AppConfig[:s3_key] && AppConfig[:s3_secret] && AppConfig[:s3_bucket]
config.storage = :s3
config.s3_access_key_id = APP_CONFIG[:s3_key]
config.s3_secret_access_key = APP_CONFIG[:s3_secret]
config.s3_bucket = APP_CONFIG[:s3_bucket]
config.s3_access_key_id = AppConfig[:s3_key]
config.s3_secret_access_key = AppConfig[:s3_secret]
config.s3_bucket = AppConfig[:s3_bucket]
config.cache_dir = "#{Rails.root}/tmp/uploads"
else
config.storage = :file

View file

@ -59,4 +59,21 @@ namespace :migrations do
end
end
end
task :upload_photos_to_s3 do
require File.join(Rails.root,"config/environment")
puts AppConfig[:s3_key]
connection = Aws::S3.new( AppConfig[:s3_key], AppConfig[:s3_secret])
bucket = connection.bucket('joindiaspora')
dir_name = File.dirname(__FILE__) + "/../../public/uploads/images/"
Dir.foreach(dir_name){|file_name| puts file_name;
if file_name != '.' && file_name != '..';
key = Aws::S3::Key.create(bucket, 'uploads/images/' + file_name);
key.put(File.open(dir_name+ '/' + file_name).read, 'public-read');
key.public_link();
end
}
end
end