<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -2,13 +2,16 @@ development:
   bucket_name: appname_development
   access_key_id: 
   secret_access_key: 
+  distribution_domain: XXXX.cloudfront.net
 
 test:
   bucket_name: appname_test
   access_key_id: 
   secret_access_key: 
+  distribution_domain: XXXX.cloudfront.net
 
 production:
   bucket_name: appname
   access_key_id: 
   secret_access_key: 
+  distribution_domain: XXXX.cloudfront.net</diff>
      <filename>amazon_s3.yml.tpl</filename>
    </modified>
    <modified>
      <diff>@@ -52,6 +52,8 @@ module Technoweenie # :nodoc:
       #      for the S3 backend.  Setting this sets the :storage to :file_system.
 
       # *  &lt;tt&gt;:storage&lt;/tt&gt; - Use :file_system to specify the attachment data is stored with the file system.  Defaults to :db_system.
+      # *  &lt;tt&gt;:cloundfront&lt;/tt&gt; - Set to true if you are using S3 storage and want to serve the files through CloudFront.  You will need to
+      #      set a distribution domain in the amazon_s3.yml config file. Defaults to false
       # *  &lt;tt&gt;:bucket_key&lt;/tt&gt; - Use this to specify a different bucket key other than :bucket_name in the amazon_s3.yml file.  This allows you to use
       #      different buckets for different models. An example setting would be :image_bucket and the you would need to define the name of the corresponding
       #      bucket in the amazon_s3.yml file.
@@ -80,6 +82,7 @@ module Technoweenie # :nodoc:
         options[:thumbnails]       ||= {}
         options[:thumbnail_class]  ||= self
         options[:s3_access]        ||= :public_read
+        options[:cloudfront]       ||= false
         options[:content_type] = [options[:content_type]].flatten.collect! { |t| t == :image ? Technoweenie::AttachmentFu.content_types : t }.flatten unless options[:content_type].nil?
 
         unless options[:thumbnails].is_a?(Hash)</diff>
      <filename>lib/technoweenie/attachment_fu.rb</filename>
    </modified>
    <modified>
      <diff>@@ -17,22 +17,28 @@ module Technoweenie # :nodoc:
       # If you don't already have your access keys, all you need to sign up for the S3 service is an account at Amazon.
       # You can sign up for S3 and get access keys by visiting http://aws.amazon.com/s3.
       #
+      # If you wish to use Amazon CloudFront to serve the files, you can also specify a distibution domain for the bucket.
+      # To read more about CloudFront, visit http://aws.amazon.com/cloudfront
+      #
       # Example configuration (RAILS_ROOT/config/amazon_s3.yml)
       #
       #   development:
       #     bucket_name: appname_development
       #     access_key_id: &lt;your key&gt;
       #     secret_access_key: &lt;your key&gt;
+      #     distribution_domain: XXXX.cloudfront.net
       #
       #   test:
       #     bucket_name: appname_test
       #     access_key_id: &lt;your key&gt;
       #     secret_access_key: &lt;your key&gt;
+      #     distribution_domain: XXXX.cloudfront.net
       #
       #   production:
       #     bucket_name: appname
       #     access_key_id: &lt;your key&gt;
       #     secret_access_key: &lt;your key&gt;
+      #     distribution_domain: XXXX.cloudfront.net
       #
       # You can change the location of the config path by passing a full path to the :s3_config_path option.
       #
@@ -59,6 +65,8 @@ module Technoweenie # :nodoc:
       # * &lt;tt&gt;:server&lt;/tt&gt; - The server to make requests to. Defaults to &lt;tt&gt;s3.amazonaws.com&lt;/tt&gt;.
       # * &lt;tt&gt;:port&lt;/tt&gt; - The port to the requests should be made on. Defaults to 80 or 443 if &lt;tt&gt;:use_ssl&lt;/tt&gt; is set.
       # * &lt;tt&gt;:use_ssl&lt;/tt&gt; - If set to true, &lt;tt&gt;:port&lt;/tt&gt; will be implicitly set to 443, unless specified otherwise. Defaults to false.
+      # * &lt;tt&gt;:distribution_domain&lt;/tt&gt; - The CloudFront distribution domain for the bucket.  This can either be the assigned
+      #     distribution domain (ie. XXX.cloudfront.net) or a chosen domain using a CNAME. See CloudFront for more details.
       #
       # == Usage
       #
@@ -150,6 +158,16 @@ module Technoweenie # :nodoc:
       #
       # Niether &lt;tt&gt;base_path&lt;/tt&gt; or &lt;tt&gt;full_filename&lt;/tt&gt; include the bucket name as part of the path.
       # You can retrieve the bucket name using the &lt;tt&gt;bucket_name&lt;/tt&gt; method.
+      # 
+      # === Accessing CloudFront URLs
+      # 
+      # You can get an object's CloudFront URL using the cloudfront_url accessor.  Using the example from above:
+      # @postcard.cloudfront_url # =&gt; http://XXXX.cloudfront.net/photos/1/mexico.jpg
+      #
+      # The resulting url is in the form: http://:distribution_domain/:table_name/:id/:file
+      #
+      # If you set :cloudfront to true in your model, the public_filename will be the CloudFront
+      # URL, not the S3 URL.
       module S3Backend
         class RequiredLibraryNotFoundError &lt; StandardError; end
         class ConfigFileNotFoundError &lt; StandardError; end
@@ -198,6 +216,10 @@ module Technoweenie # :nodoc:
         def self.port_string
           @port_string ||= (s3_config[:port].nil? || s3_config[:port] == (s3_config[:use_ssl] ? 443 : 80)) ? '' : &quot;:#{s3_config[:port]}&quot;
         end
+        
+        def self.distribution_domain
+          @distribution_domain = s3_config[:distribution_domain]
+        end
 
         module ClassMethods
           def s3_protocol
@@ -211,6 +233,10 @@ module Technoweenie # :nodoc:
           def s3_port_string
             Technoweenie::AttachmentFu::Backends::S3Backend.port_string
           end
+          
+          def cloudfront_distribution_domain
+            Technoweenie::AttachmentFu::Backends::S3Backend.distribution_domain
+          end
         end
 
         # Overwrites the base filename writer in order to store the old filename
@@ -249,7 +275,27 @@ module Technoweenie # :nodoc:
         def s3_url(thumbnail = nil)
           File.join(s3_protocol + s3_hostname + s3_port_string, bucket_name, full_filename(thumbnail))
         end
-        alias :public_filename :s3_url
+        
+        # All public objects are accessible via a GET request to CloudFront. You can generate a
+        # url for an object using the cloudfront_url method.
+        #
+        #   @photo.cloudfront_url
+        #
+        # The resulting url is in the form: &lt;tt&gt;http://:distribution_domain/:table_name/:id/:file&lt;/tt&gt; using
+        # the &lt;tt&gt;:distribution_domain&lt;/tt&gt; variable set in the configuration parameters in &lt;tt&gt;RAILS_ROOT/config/amazon_s3.yml&lt;/tt&gt;.
+        #
+        # The optional thumbnail argument will output the thumbnail's filename (if any).
+        def cloudfront_url(thumbnail = nil)
+          &quot;http://&quot; + cloudfront_distribution_domain + &quot;/&quot; + full_filename(thumbnail)
+        end
+        
+        def public_filename(*args)
+          if attachment_options[:cloudfront]
+            cloudfront_url(args)
+          else
+            s3_url(args)
+          end
+        end
 
         # All private objects are accessible via an authenticated GET request to the S3 servers. You can generate an
         # authenticated url for an object like this:
@@ -301,6 +347,10 @@ module Technoweenie # :nodoc:
         def s3_port_string
           Technoweenie::AttachmentFu::Backends::S3Backend.port_string
         end
+        
+        def cloudfront_distribution_domain
+          Technoweenie::AttachmentFu::Backends::S3Backend.distribution_domain
+        end
 
         protected
           # Called in the after_destroy callback</diff>
      <filename>lib/technoweenie/attachment_fu/backends/s3_backend.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ab1e4f7b0b9de85e0c9decf061d2ef5c1dc0feaa</id>
    </parent>
  </parents>
  <author>
    <name>Micah Wedemeyer</name>
    <email>micah@aisleten.com</email>
  </author>
  <url>http://github.com/technoweenie/attachment_fu/commit/48639bfdf142eefe2a32b54a09a039b924fcc3e7</url>
  <id>48639bfdf142eefe2a32b54a09a039b924fcc3e7</id>
  <committed-date>2009-03-15T09:33:34-07:00</committed-date>
  <authored-date>2009-03-15T09:33:34-07:00</authored-date>
  <message>Updated attachment_fu to add CloudFront support.</message>
  <tree>f6bd5a1756b84add79ff86dfeebbc31dc85aa807</tree>
  <committer>
    <name>Micah Wedemeyer</name>
    <email>micah@aisleten.com</email>
  </committer>
</commit>
