<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>UK Ruby on Rails, Exalead, AWS, Consultancy - Protecting your Paperclip downloads Comments</title>
  <id>tag:thewebfellas.com,2011:/blog/2009/8/29/protecting-your-paperclip-downloads/comments</id>
  <generator version="0.7.3" uri="http://mephistoblog.com">Mephisto Noh-Varr</generator>
  <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads/comments.xml" rel="self" type="application/atom+xml"/>
  <link href="/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
  <updated>2011-05-23T13:33:28Z</updated>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Matt</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:27154</id>
    <published>2011-05-21T22:26:19Z</published>
    <updated>2011-05-21T22:26:19Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Matt</title>
<content type="html">&lt;p&gt;Hi!&lt;/p&gt;

&lt;p&gt;Very nice this tutorial and explanations!
But I have a problem with capistrano deployment. How could I symlink the folder outside the public folder, which contains my uploads? I don't use S3.&lt;/p&gt;

&lt;p&gt;Anyone an idea?&lt;/p&gt;

&lt;p&gt;Matt&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Rob Anderton</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:27045</id>
    <published>2011-05-16T16:44:15Z</published>
    <updated>2011-05-16T16:44:15Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Rob Anderton</title>
<content type="html">&lt;p&gt;@Justin: sorry I missed your question - you've probably figured something out by now. If you're using a newer version of Paperclip, the &lt;code&gt;expiring_url&lt;/code&gt; method is now part of the attachment model, so each one would have its own copy of the method.&lt;/p&gt;

&lt;p&gt;Using older versions of Paperclip, probably the easiest thing to do would be to modify the code to accept the attachment object as a parameter too:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def download_url(attachment, style = nil, include_updated_timestamp = true)
  url = Paperclip::Interpolations.interpolate('/:class/:id/:style.:extension', attachment, style || attachment.default_style)
  include_updated_timestamp &amp;&amp; attachment.updated_at ? [url, attachment.updated_at].compact.join(url.include?(&quot;?&quot;) ? &quot;&amp;&quot; : &quot;?&quot;) : url
end

def authenticated_url(attachment, style = nil, expires_in = 10.seconds)
  AWS::S3::S3Object.url_for(attachment.path(style || attachment.default_style), attachment.bucket_name, :expires_in =&gt; expires_in, :use_ssl =&gt; attachment.s3_protocol == 'https')
end&lt;/code&gt;&lt;/pre&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Rob Anderton</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:27044</id>
    <published>2011-05-16T16:27:34Z</published>
    <updated>2011-05-16T16:27:34Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Rob Anderton</title>
<content type="html">&lt;p&gt;@Paul yep it's a typo: if we had a prize for paying attention you'd win it as nobody else has spotted the goof in the last couple of years!&lt;/p&gt;

&lt;p&gt;@AdamGold: glad to help! The authenticated URL is time based, so by setting a short expiry time (for example the 10 seconds I've used in the examples above) you give time to allow the client to access the data but once the 10 seconds have elapsed the link no longer works (so sharing with friends would be pointless, unless they can use it within the 10 seconds!). I'm not aware of any way of having a one-time URL instead.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>AdamGold</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:27028</id>
    <published>2011-05-15T16:21:41Z</published>
    <updated>2011-05-15T16:21:41Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by AdamGold</title>
<content type="html">&lt;p&gt;You're one of the bests ;) Really good article Rob, only I have one question - How can I re-generate the link each time? I mean, I want it to be expired -&gt; re-generated so the user won't be able to share it with friends. Is it possible?
Thanks!&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:26642</id>
    <published>2011-04-26T17:19:00Z</published>
    <updated>2011-04-26T17:19:00Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Paul</title>
<content type="html">&lt;p&gt;Wow, thank you for writing this up! It's a great work-around for the (understandable) limitations of S3 access control.&lt;/p&gt;

&lt;p&gt;I think this is a mental typo, right?:&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;And while I’m at it, I can also move the authenticated S3 URL generation
    out of the model and into the controller too.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I believe that should read:&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;And while I’m at it, I can also move the authenticated S3 URL generation
    out of the controller and into the model too.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Paul&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Justin</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:21459</id>
    <published>2010-12-09T23:22:31Z</published>
    <updated>2010-12-09T23:22:31Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Justin</title>
<content type="html">&lt;p&gt;I was able to get this working successfully, though I have run into some problems when trying to do this with multiple attachments on the same model.  What would I need to do to be able to do this with two attachments, for example we already have an mp3, what if I wanted to upload a jpg also?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Rob Anderton</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:21312</id>
    <published>2010-12-07T23:30:01Z</published>
    <updated>2010-12-07T23:30:01Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Rob Anderton</title>
<content type="html">&lt;p&gt;It's annoyingly tricky to find a clear definition of this, but after some Googling the simple answer is yes with authenticated-read anyone with an S3 account could access the object (assuming they knew the name of the bucket and object). A better option would therefore be to use the private policy, which means only a user authenticating with your id and secret access key can access the object.&lt;/p&gt;

&lt;p&gt;I'd like to do a bit more reading on this though, as authenticated-read seems to be the policy most commonly referenced in other blogs and articles, which makes me wonder why the private policy isn't more popular.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Brett</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:21178</id>
    <published>2010-12-03T17:27:51Z</published>
    <updated>2010-12-03T17:27:51Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Brett</title>
<content type="html">&lt;p&gt;Great post, just struggling to understand the part about: &quot;authenticated-read—Owner gets FULL_CONTROL, and any principal authenticated as a registered Amazon S3 user is granted READ access&quot;&lt;/p&gt;

&lt;p&gt;The goal is to protect you files from unauthorized use so by &quot;authenticated-read&quot; does that provide access to any Amazon S3 user?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Rob Anderton</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:20726</id>
    <published>2010-11-13T23:27:35Z</published>
    <updated>2010-11-13T23:27:35Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Rob Anderton</title>
<content type="html">&lt;p&gt;Glad you figured it out, and thanks for the compliments. Just to confirm the solution in case anybody else needs it: the &lt;code&gt;:target&lt;/code&gt; option should be in the call to &lt;code&gt;link_to&lt;/code&gt; in the view, not in the &lt;code&gt;authenticated_url&lt;/code&gt; method in the model. For example:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&amp;lt%= link_to('Listen', track.download_url, :target =&amp;gt; &quot;_blank&quot;) %&amp;gt;&lt;/code&gt;&lt;/pre&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Sandy</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:20530</id>
    <published>2010-11-07T18:09:54Z</published>
    <updated>2010-11-07T18:09:54Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Sandy</title>
<content type="html">&lt;p&gt;I figured it out.  The &quot;redirect&quot; in the controller was occuring before the new window opened, so you have to open the new window prior to performing the &quot;redirect&quot;.&lt;/p&gt;

&lt;p&gt;Great tutorial.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Sandy</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:20452</id>
    <published>2010-11-05T15:43:19Z</published>
    <updated>2010-11-05T15:43:19Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Sandy</title>
<content type="html">&lt;p&gt;Thank you for an excellent job explaining the unexplainable.&lt;/p&gt;

&lt;p&gt;I have a question which I have (so far) been unable to solve.  I want the secure download to open in a new window.  However, if I add &lt;/p&gt;

&lt;p&gt;:target =&gt; &quot;_blank&quot;&lt;/p&gt;

&lt;p&gt;to the authenticated_url, as&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;AWS::S3::S3Object.url_for(matter.path(style || matter.default_style), matter.bucket_name, :expires_in =&gt; expires_in, :use_ssl =&gt; matter.s3_protocol == 'https', :target =&gt; &quot;_blank&quot;)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;the browser is simply doing a redirect (ignoring the :target =&gt; &quot;_blank&quot;), rather than opening a new window.  Is there some other way to do that?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>aknagi</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:18788</id>
    <published>2010-09-04T22:37:09Z</published>
    <updated>2010-09-04T22:37:09Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by aknagi</title>
<content type="html">&lt;p&gt;Thank you for a fantastic high quality howto. You &lt;em&gt;ROCK&lt;/em&gt;.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Rob Anderton</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:14201</id>
    <published>2010-03-20T09:08:53Z</published>
    <updated>2010-03-20T09:08:53Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Rob Anderton</title>
<content type="html">&lt;p&gt;You can use the &lt;code&gt;:requirements&lt;/code&gt; option in &lt;kbd&gt;routes.rb&lt;/kbd&gt; to allow (almost) any character in the params, for example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;map.connect 'tracks/:id/:style', 
  :controller =&amp;gt; 'tracks', 
  :action =&amp;gt; 'download', 
  :conditions =&amp;gt; { :method =&amp;gt; :get }, 
  :requirements =&amp;gt; { :style =&amp;gt; /.*/ }&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that this means &lt;code&gt;:format&lt;/code&gt; is no longer available as a parameter, so you'll have to manually split the &lt;code&gt;:style&lt;/code&gt; yourself if necessary.&lt;/p&gt;
&lt;p&gt;Using the above with a URL like &lt;samp&gt;/tracks/1/.sample.mp3&lt;/samp&gt; would set &lt;code&gt;params&lt;/code&gt; to &lt;code&gt;{ :id =&amp;gt; 1, :style =&amp;gt; &quot;.sample.mp3&quot; }&lt;/code&gt;.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Denton Vis</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:14185</id>
    <published>2010-03-19T15:22:34Z</published>
    <updated>2010-03-19T15:22:34Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Denton Vis</title>
<content type="html">&lt;p&gt;thanks for the insightful post.
But i am having a problem downloading files with names begin with a period. For example, a file with a name like '.bzr.log' would result in a Routing Error 'no route found'. 
Any ideas on how to remedy this?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Yuval</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:13361</id>
    <published>2010-02-15T18:52:03Z</published>
    <updated>2010-02-15T18:52:03Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Yuval</title>
<content type="html">&lt;p&gt;Blast from the past!&lt;/p&gt;

&lt;p&gt;I've returned to this project, and decided to have a go at the variable url/path depending on whether you were requesting the original file or not. In my situation, I am protecting PDFs while making thumbnails etc publicly accessible. The following code is working well, using the same controller action and permissions as in the original article.&lt;/p&gt;

&lt;p&gt;config/initializers/plugin_options.rb&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;Paperclip::Attachment.default_options.merge!(
  :url =&amp;gt; '/system/:class/:attachment/:id/:style/:filename',
  :path =&amp;gt; ':rails_root/public:url')

Paperclip.interpolates :variable_url do |attachment, style|
  style == :original ? '/pdfs/:id' : Paperclip::Attachment.default_options[:url]
end

Paperclip.interpolates :variable_path do |attachment, style|
  style == :original ? ':rails_root/assets/:class/:id/:filename' : Paperclip::Attachment.default_options[:path]
end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;/models/product.rb&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;has_attached_file :image,
    :styles =&amp;gt; {:thumb =&amp;gt; ['300&amp;gt;', :jpg], :large =&amp;gt; ['620&amp;gt;', :jpg]},
    :default_style =&amp;gt; :large,
    :url =&amp;gt; ':variable_url',
    :path =&amp;gt; ':variable_path'&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;/config/routes.rb&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;map.original_pdf 'pdfs/:id', :controller =&amp;gt; 'admin/products', :action =&amp;gt; 'original_pdf'&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then on the admin page view I am using the following to show a thumbnail and link to the protected PDF:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&amp;lt;%= link_to image_tag(product.image.url(:thumb)), product.image.url(:original) %&amp;gt;&lt;/code&gt;&lt;/pre&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Rob Anderton</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:12558</id>
    <published>2010-01-13T10:42:29Z</published>
    <updated>2010-01-13T10:42:29Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Rob Anderton</title>
<content type="html">&lt;p&gt;@Yuval: good idea. I think the tricky part is that Paperclip doesn't currently support per-style URLs. In the meantime you could maybe still route them through the download action and make the &lt;code&gt;downloadable?&lt;/code&gt; check only happen if the style is &lt;code&gt;:original&lt;/code&gt;.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Yuval</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:12244</id>
    <published>2010-01-04T03:59:40Z</published>
    <updated>2010-01-04T03:59:40Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Yuval</title>
<content type="html">&lt;p&gt;A great addition to this article would be a two tier approach, where the original asset is protected but its thumbnail/preview is publicly visible/accessible. Cheers.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Rob Anderton</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:11448</id>
    <published>2009-12-06T23:14:41Z</published>
    <updated>2009-12-06T23:14:41Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Rob Anderton</title>
<content type="html">&lt;p&gt;@Georg: that's good news although it doesn't seem to allow for generating urls for different styles, or supporting https access, so might be worth submitting a patch for that.&lt;/p&gt;

&lt;p&gt;@Laran: first thing to check is that the right url is being used for the redirect and also check that the uploaded files have the correct permissions (using an S3 file browser like s3fox for Firefox).&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Laran Evans</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:11368</id>
    <published>2009-12-03T20:55:32Z</published>
    <updated>2009-12-03T20:55:32Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Laran Evans</title>
<content type="html">&lt;p&gt;Great tutorial. I've implemented the S3 approach for my attachment model. But when I click on the link to download my file from S3 I keep getting an AccessDenied error.&lt;/p&gt;

&lt;p&gt;Any thoughts on how to resolve this?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Georg Ledermann</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:11271</id>
    <published>2009-12-01T15:29:24Z</published>
    <updated>2009-12-01T15:29:24Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Georg Ledermann</title>
<content type="html">&lt;p&gt;Regarding the authenticated_url: The &lt;a href=&quot;http://github.com/thoughtbot/paperclip/commit/808d295086a8d363e69daed1f57449164c0232e4&quot;&gt;latest Paperclip commit&lt;/a&gt; added the method &quot;expired_url&quot; which enables the feature out of the box.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Hates_</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:9270</id>
    <published>2009-10-15T23:53:19Z</published>
    <updated>2009-10-15T23:53:19Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Hates_</title>
<content type="html">&lt;p&gt;Brilliant write up! Just what I needed to get my Paperclip S3 stuff working how I wanted.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Dave Mauldin</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:8844</id>
    <published>2009-09-24T16:49:41Z</published>
    <updated>2009-09-24T16:49:41Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Dave Mauldin</title>
<content type="html">&lt;p&gt;I'm not actually going to use much of this article yet, but still feel compelled to leave a comment on how awesome this article is.  Thanks a ton for taking the time to write this up.  Amazing.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Georg Ledermann</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:8816</id>
    <published>2009-09-23T12:14:39Z</published>
    <updated>2009-09-23T12:14:39Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Georg Ledermann</title>
<content type="html">&lt;p&gt;Thanks for this article! Just a hint: Instead of writing a method &quot;authenticated_url&quot; in every model which uses Paperclip it's more DRY to monkey patch Paperclip like this:&lt;/p&gt;

&lt;p&gt;http://gist.github.com/191937&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Rob Anderton</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:8572</id>
    <published>2009-09-11T16:04:46Z</published>
    <updated>2009-09-11T16:04:46Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Rob Anderton</title>
<content type="html">&lt;p&gt;@Trevor, Hakan &amp;amp; Yuval: glad you liked it!&lt;/p&gt;
&lt;p&gt;@Thibaut: that's a good question, the answer depends on your storage method:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;If you're using the file system storage module then you shouldn't need to do anything as Rails sets the &lt;code&gt;Content-Disposition&lt;/code&gt; header to &lt;samp&gt;attachment&lt;/samp&gt; when using the &lt;code&gt;send_file&lt;/code&gt; method. Internet Explorer may still insist on showing the file inline though, so you could also use a bit of brute force and set the &lt;code&gt;Content-Type&lt;/code&gt; header to &lt;samp&gt;application/octet-stream&lt;/samp&gt; in the controller:&lt;/p&gt;
    &lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;send_file_options = { :type =&gt; 'application/octet-stream' }&lt;/code&gt;&lt;/pre&gt;
    &lt;p&gt;If you were feeling clever you could of course use a bit of simple browser sniffing to return the correct &lt;code&gt;Content-Type&lt;/code&gt; for intelligent browsers and the &lt;samp&gt;application/octet-stream&lt;/samp&gt; header for IE.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;If you're using the S3 storage module then you need to add the &lt;code&gt;s3_headers&lt;/code&gt; option to your &lt;code&gt;has_attached_file&lt;/code&gt; definition in your models:&lt;/p&gt;
    &lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;has_attached_file :mp3,
                  :url =&gt; ':s3_domain_url',
                  :path =&gt; 'assets/:class/:id/:style.:extension',
                  :storage =&gt; :s3,
                  :s3_credentials =&gt; File.join(Rails.root, 'config', 's3.yml'),
                  :s3_permissions =&gt; 'authenticated-read',
                  :s3_protocol =&gt; 'http',
                  :s3_headers =&gt; { :content_disposition =&gt; 'attachment' }&lt;/code&gt;&lt;/pre&gt;
    &lt;p&gt;When the controller redirects to the S3 URL, Amazon will send the header you specify here, forcing the download. As with file system storage you can also force the &lt;code&gt;Content-Type&lt;/code&gt; header using this method, although you won't be able to use any kind of browser sniffing to select content type based on the user's browser:&lt;/p&gt;
    &lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;has_attached_file :mp3,
                  :url =&gt; ':s3_domain_url',
                  :path =&gt; 'assets/:class/:id/:style.:extension',
                  :storage =&gt; :s3,
                  :s3_credentials =&gt; File.join(Rails.root, 'config', 's3.yml'),
                  :s3_permissions =&gt; 'authenticated-read',
                  :s3_protocol =&gt; 'http',
                  :s3_headers =&gt; { :content_type =&gt; 'application/octet-stream', :content_disposition =&gt; 'attachment' }&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;
&lt;/ul&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Thibaut Assus</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:8568</id>
    <published>2009-09-11T09:06:49Z</published>
    <updated>2009-09-11T09:06:49Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Thibaut Assus</title>
<content type="html">&lt;p&gt;Cool,
But there is a problem here :
It is not a send_data, so the user get the file directly in his browser...
How could I change that for the user to have a Force-Download file ?
Thank you !&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Yuval</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:8532</id>
    <published>2009-09-08T15:27:08Z</published>
    <updated>2009-09-08T15:27:08Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Yuval</title>
<content type="html">&lt;p&gt;Holy crap. I stumbled upon this today while search for another paperclip question, and it's exactly what I was looking for last week. Thanks for saving me some hours!&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Hakan Ensari</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:8520</id>
    <published>2009-09-08T00:06:20Z</published>
    <updated>2009-09-08T00:06:20Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Hakan Ensari</title>
<content type="html">&lt;p&gt;Awesome. Thanks.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://thewebfellas.com/">
    <author>
      <name>Trevor Turk</name>
    </author>
    <id>tag:thewebfellas.com,2009-08-29:8374:8430</id>
    <published>2009-09-01T16:59:46Z</published>
    <updated>2009-09-01T16:59:46Z</updated>
    <category term="Blog"/>
    <link href="http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads" rel="alternate" type="text/html"/>
    <title>Comment on 'Protecting your Paperclip downloads' by Trevor Turk</title>
<content type="html">&lt;p&gt;Amazing write-up. Thanks very much!&lt;/p&gt;</content>  </entry>
</feed>

