Class: Binda::Image::ImageUploader

Inherits:
CarrierWave::Uploader::Base
  • Object
show all
Includes:
CarrierWave::MiniMagick
Defined in:
app/uploaders/binda/image/image_uploader.rb

Instance Method Summary collapse

Instance Method Details

#cache_dirObject



22
23
24
# File 'app/uploaders/binda/image/image_uploader.rb', line 22

def cache_dir
  "#{Rails.root}/tmp/uploads"
end

#content_type_whitelistObject

Add a white list of extensions which are allowed to be uploaded. For images you might use something like this: def extension_whitelist

%w(jpg jpeg gif png)

end



60
61
62
# File 'app/uploaders/binda/image/image_uploader.rb', line 60

def content_type_whitelist
  /image\//
end

#register_detailsObject



78
79
80
81
82
83
# File 'app/uploaders/binda/image/image_uploader.rb', line 78

def register_details
  if file && model
    model.content_type = file.content_type if file.content_type
    model.file_size = file.size
  end
end

#register_image_detailsObject



71
72
73
74
75
# File 'app/uploaders/binda/image/image_uploader.rb', line 71

def register_image_details
  if file && model
    model.file_width, model.file_height = ::MiniMagick::Image.open(file.file)[:dimensions]
  end
end

#store_dirObject

Override the directory where uploaded files will be stored. This is a sensible default for uploaders that are meant to be mounted:



17
18
19
# File 'app/uploaders/binda/image/image_uploader.rb', line 17

def store_dir
  "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end