Class: ProtectedMediaController

Inherits:
Spud::ApplicationController
  • Object
show all
Defined in:
app/controllers/protected_media_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/protected_media_controller.rb', line 5

def show
  @media = SpudMedia.where(:id => params[:id]).first
  if @media.blank?
    flash[:error] = "The requested file could not be found"
    redirect_to(root_url)
  else
    if Spud::Media.config.paperclip_storage == :s3
      secure_url = @media.attachment.s3_object(params[:style]).url_for(:read, :secure => true, :expires => 10.minutes)
      redirect_to(secure_url.to_s)
    else
      filepath = File.join(Rails.root, @media.attachment.path(params[:style]))
      if !File.exists?(filepath)
        flash[:error] = "The requested file could not be found"
        redirect_to root_path
      else
        send_file(filepath, :disposition => 'inline')
      end
    end
  end
end