Skip to content

Instantly share code, notes, and snippets.

@jonpaul
Created July 30, 2012 18:54
Show Gist options
  • Save jonpaul/3209145 to your computer and use it in GitHub Desktop.
Save jonpaul/3209145 to your computer and use it in GitHub Desktop.
sr3 permalinks as attachments
# gets permalink for file on s3
#
# *Parameters:*
# (+String+) -- aws_path full path of key to be uploaded to AWS (usually generated)
#
# *Returns:*
# (+String+) -- url
def self.get_permalink(aws_path, content_type = nil, content_disposition = nil)
return nil if aws_path.blank?
s3 = AWS::S3.new
b = s3.buckets[@bucket]
# b = s3.buckets.create(@bucket)
o = b.objects[aws_path]
return o.url_for(:read, :expires => 24.hours, :response_content_type => content_type, :response_content_disposition => content_disposition).to_s
end
@chebyte
Copy link

chebyte commented Jul 30, 2012

def download
@attachment = Attachment.find(params[:id])
redirect_to @attachment.resource.expiring_url(10)
end

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