Module: Ext::S3Link

Included in:
Member
Defined in:
app/models/ext.rb

Instance Method Summary collapse

Instance Method Details



39
40
41
42
43
44
45
46
47
48
# File 'app/models/ext.rb', line 39

def download_link_for(field)
  s3 = AWS::S3.new(
      :access_key_id     => ENV['S3_ACCESS_KEY_ID'],
      :secret_access_key => ENV['S3_SECRET_ACCESS_KEY']
  )
  bucket = s3.buckets[ENV['S3_BUCKET']]
  object = bucket.objects[self.send(field).path]
  url    = object.url_for(:read, :expires => 10*60)
  url.to_s
end