Created
February 5, 2018 15:00
-
-
Save hkraji/8e63d3b25d131cf03fe9806af5dca319 to your computer and use it in GitHub Desktop.
Connect to S3 and Create files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rake' | |
require 'ap' | |
namespace :gazzda_s3 do | |
desc 'Upload images from directory to specified s3 bucket' | |
task :upload, [:bucket] do |t, args| | |
path_to_images = '/Users/haris/rails/scm_gazzda/image-files' | |
bucket = args[:bucket] | |
connection = Fog::Storage.new({ :provider => "AWS", :aws_access_key_id => ENV['AWS_KEY_ID'], :aws_secret_access_key => ENV['AWS_KEY_SECRET'], :region => 'eu-central-1' }) | |
directory = connection.directories.get(bucket) | |
Dir.glob("#{path_to_images}/**/*").each do |entry| | |
if File.file?(entry) | |
short_path = entry.gsub(path_to_images, '') | |
print "Creating ... #{short_path} ..." | |
file = directory.files.create( | |
:key => short_path, | |
:body => File.read(entry) | |
) | |
puts 'Finished!' | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment