s3-publisher

S3Publisher is meant as a clean, simple, sensible-defaults way to publish files to Amazon S3 for the world to see.

Basic usage:

require 's3-publisher'
S3Publisher.publish('my-bucket') do |p|
    p.push('test.txt', 'abc1234')
end

This will:

  • push test.txt to my-bucket.s3.amazonaws.com

  • set security to public-read

  • gzip contents (‘abc1234’) and set a Content-Encoding: gzip header so clients know to decompress

  • set a Cache-Control: max-age=5 header

Slightly more advanced example:

S3Publisher.publish('my-bucket', :base_path => 'world_cup') do |p|
    p.push('events.xml', '<xml>...', :ttl => 15)
end

In this example:

  • file will be written to my-bucket.s3.amazonaws.com/world_cup/events.xml

  • Cache-Control: max-age=15 will be set

A few miscellaneous notes:

  • gzip compress is skipped on .jpg/gif/png/tif files

  • uploads are multi-threaded. You can control worker thread count on instantiation.

  • pass :redundancy => :reduced when instantiating the publisher to write to reduced

redundancy storage (this used to be the default, but now requires the option to be set.)

See class docs for further options.

Copyright © 2011 Ben Koski. See LICENSE for details.