added a task to upload
This commit is contained in:
parent
7477a22421
commit
0f9dc4954a
2 changed files with 21 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue