Class: Cms::Attachments::S3Strategy

Inherits:
Object
  • Object
show all
Defined in:
lib/cms/attachments/s3_strategy.rb

Overview

Automatically used to serve files when the following configuration is set:

config.cms.attachments.storage = :s3

Class Method Summary collapse

Class Method Details

.attachments_storage_locationObject

For S3, this returns the relative path within the bucket. I.e. s3.amazonaws.com/:bucket/:attachments_storage_location/:path_to_file



25
26
27
# File 'lib/cms/attachments/s3_strategy.rb', line 25

def self.attachments_storage_location
  "/attachments"
end

.send_attachment(attachment, controller) ⇒ Object

Redirects users to the file on S3.

Issues:
  1. No security, all files are assumed to be public
  2. CNAMEs are not supported.


12
13
14
15
16
17
18
19
20
21
# File 'lib/cms/attachments/s3_strategy.rb', line 12

def self.send_attachment(attachment, controller)
  controller.redirect_to attachment.url
  
  # Possible s3_cname implementation
  # if Cms::S3.options[:s3_cname]
   # redirect_to("http://#{Cms::S3.options[:s3_cname]}/#{@attachment.file_location}")
  # else
  # redirect_to("http://#{Cms::S3.options[:bucket]}.s3.amazonaws.com/#{@attachment.file_location}")
  # end
end