samples/s3.rb in simple_aws-1.2.0 vs samples/s3.rb in simple_aws-1.2.1
- old
+ new
@@ -20,10 +20,11 @@
puts " ruby sample/s3.rb [bucket name] [file to use]"
exit 1
end
s3 = SimpleAWS::S3.new ENV["AWS_KEY"], ENV["AWS_SECRET"]
+s3.debug!
bucket_name = ARGV[0]
file_name = ARGV[1]
puts "All buckets in this account:", ""
@@ -34,11 +35,19 @@
puts "", "First 10 files in #{bucket_name}:", ""
bad_usage unless bucket_name
-s3.get("/", :bucket => bucket_name, :params => {"max-keys" => 10}).contents.each do |entry|
- puts entry.key
+s3.get("/", :bucket => bucket_name, :params => {"max-keys" => 10}).tap do |response|
+ # Amazon doesn't include Contents if there are no files
+ # Amazon also includes just one entry if there's only one file to be found,
+ # where as if there's > 1 then SimpleAWS will be given a proper array.
+ # Gotta love XML!
+ if response["Contents"]
+ [response.contents].flatten.each do |entry|
+ puts entry.key
+ end
+ end
end
puts "", "Uploading #{file_name} to #{bucket_name}:", ""
bad_usage unless file_name