I have a script that is supposed to upload a local folder to s3 using aws-sdk and ruby. As much as I understand from ruby, the files need to be uploaded one by one, so here is the code used:
require 'aws-sdk'
require 'open3'
s3_bucket = ARGV[0]
debug = ARGV[1] || nil
@s3 = Aws::S3::Client.new(region: 'eu-west-1')
files = Dir[ File.join('srv', '**', '*') ].reject { |p| File.directory? p }
files.each do |f|
o, e, s = Open3.capture3("gio info -a standard::content-type #{f}")
abort(e) unless s.to_s.match(/exit 0/)
content_type = o.split('standard::content-type: ')[1].strip
s3_key = f.split('srv/lila/')[1]
puts "Uploading #{f} with content-type #{content_type}" if debug
File.open(f,'rb') do |file|
@s3.put_object({body: file, content_type: content_type, bucket: s3_bucket, key: s3_key})
end
end
My local file name is like this: srv/lila/1.1.1/somename/index.html
Somehow, only the file name is uploaded, and not the content.So when I go to the URL, I can see the name of the file as the content srv/lila/1.1.1/somename/index.html
. My ruby knowledge is limited and I am not sure what is wrong in this script. Can you help please?