Posted By

sudarkoff on 11/30/06


Tagged

ruby upload amazon s3


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

hkmd
maxkks
zemariamm
webstic


Simple File Upload to Amazon S3 From Ruby


 / Published in: Ruby
 

URL: http://www.rubyinside.com/simple-file-upload-to-amazon-s3-from-ruby-313.html

Just name it s3cp (or similar), chmod it, and then you can do stuff like:

s3cp ~/somefile.whatever bucket

  1. #!/usr/bin/env ruby
  2.  
  3. require 'rubygems'
  4. require 'aws/s3'
  5.  
  6. local_file = ARGV[0]
  7. bucket = ARGV[1]
  8. mime_type = ARGV[2] || "application/octet-stream"
  9.  
  10. AWS::S3::Base.establish_connection!(
  11. :access_key_id => 'REPLACE_ME',
  12. :secret_access_key => 'REPLACE_ME'
  13. )
  14.  
  15. base_name = File.basename(local_file)
  16.  
  17. puts "Uploading #{local_file} as '#{base_name}' to '#{bucket}'"
  18.  
  19. AWS::S3::S3Object.store(
  20. base_name,
  21. File.open(local_file),
  22. bucket,
  23. :content_type => mime_type
  24. )
  25.  
  26. puts "Uploaded!"

Report this snippet  

You need to login to post a comment.