Sha256: 09205617a00c8196b63909633e2fadf4580cf791405ba82e79ea4ade7f4bb1b1

Contents?: true

Size: 699 Bytes

Versions: 2

Compression:

Stored size: 699 Bytes

Contents

class ProtectedMediaController < Spud::ApplicationController

  before_action :require_user

  def show
    @media = SpudMedia.where(id: params[:id]).first
    if @media.blank?
      raise Spud::NotFoundError, item: 'media'
    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 = @media.attachment.path(params[:style])
        if !File.exist?(filepath)
          raise Spud::NotFoundError, item: 'media'
        else
          send_file(filepath, disposition: 'inline')
        end
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tb_media-1.3.0 app/controllers/protected_media_controller.rb
tb_media-1.3.beta1 app/controllers/protected_media_controller.rb