<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Ruby on Rails, JRuby, AWS, EC2, Exalead - Protecting your Paperclip downloads Comments</title>
  <id>tag:thewebfellas.com,2010:/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>2010-03-20T09:08:53Z</updated>
  <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>
