attachment_uploader.rb 738 Bytes
Newer Older
gitlabhq's avatar
gitlabhq committed
1 2 3 4 5 6
# encoding: utf-8

class AttachmentUploader < CarrierWave::Uploader::Base
  storage :file

  def store_dir
7
    "#{Rails.root}/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
gitlabhq's avatar
gitlabhq committed
8 9
  end

10
  def image?
11
    img_ext = %w(png jpg jpeg gif bmp tiff)
12
    if file.respond_to?(:extension)
13
      img_ext.include?(file.extension.downcase)
14 15
    else
      # Not all CarrierWave storages respond to :extension
16
      ext = file.path.split('.').last.downcase
17 18 19 20
      img_ext.include?(ext)
    end
  rescue
    false
21
  end
22 23

  def secure_url
24
    Gitlab.config.gitlab.relative_url_root + "/files/#{model.class.to_s.underscore}/#{model.id}/#{file.filename}"
25 26 27 28
  end

  def file_storage?
    self.class.storage == CarrierWave::Storage::File
29
  end
gitlabhq's avatar
gitlabhq committed
30
end