Skip to content

Instantly share code, notes, and snippets.

@ledermann
Created September 23, 2009 12:01
Show Gist options
  • Save ledermann/191937 to your computer and use it in GitHub Desktop.
Save ledermann/191937 to your computer and use it in GitHub Desktop.
# Building authenticated and expiring URL for S3
# Based on
# http://github.com/logandk/paperclip_hacks/blob/master/lib/paperclip.rb
# and
# http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads
module Paperclip
class Attachment
def authenticated_url(style = nil, expires_in = 5.minutes)
if @storage.to_s == 's3' && file?
AWS::S3::S3Object.url_for(path(style || default_style), bucket_name, :expires_in => expires_in, :use_ssl => s3_protocol == 'https')
else
url
end
end
end
end
@asn
Copy link

asn commented Apr 8, 2011

Nice ! thx for this gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment