photomix/app/uploaders/file_uploader.rb

99 lines
2.8 KiB
Ruby
Raw Normal View History

# encoding: utf-8
class FileUploader < CarrierWave::Uploader::Base
2012-07-24 23:26:16 +02:00
@@generate_file_name = ''
@@original_filename = ''
2012-07-27 01:08:25 +02:00
# Include RMagick or ImageScience support
# include CarrierWave::RMagick
# include CarrierWave::ImageScience
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader
if ENV['S3_KEY']
2011-05-08 14:59:52 +02:00
storage :fog
2010-04-14 07:00:48 +02:00
def cache_dir
2011-04-25 11:38:10 +02:00
"#{Rails.root.to_s}/tmp/uploads" if ENV['HEROKU'] == 'true'
2010-04-14 07:00:48 +02:00
end
else
storage :file
end
# Override the directory where uploaded files will be stored
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
#{}"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
2012-07-24 23:26:16 +02:00
ENV['STORAGE_PATH'] + "/files/#{model.album.path}/#{model.id}"
end
def filename
unless @@original_filename == original_filename
@@original_filename = original_filename
@@generate_file_name = "#{::SecureRandom.hex(8)}#{File.extname(original_filename).downcase}" if original_filename
end
@@generate_file_name
end
# Provide a default URL as a default if there hasn't been a file uploaded
# def default_url
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded.
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files
2012-07-29 00:33:03 +02:00
version :thumb do
2012-07-24 23:26:16 +02:00
process :resize_to_fill => [260, 180]
def store_dir
2012-07-24 23:26:16 +02:00
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}/#{model.id}"
end
end
2012-07-24 23:26:16 +02:00
2012-07-26 22:26:23 +02:00
######################################################################################################################
# Note
# The default grid system provided in Bootstrap utilizes 12 columns that
# render out at widths of 724px, 940px (default without responsive CSS included), and 1170px.
# Below 767px viewports, the columns become fluid and stack vertically.
version :middle do
2012-07-27 01:08:25 +02:00
process :resize_to_fill => [742, 500]
2012-07-26 22:26:23 +02:00
def store_dir
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}/#{model.id}"
end
end
version :large do
2012-07-27 01:08:25 +02:00
process :resize_to_fill => [940, 600]
def store_dir
2012-07-24 23:26:16 +02:00
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}/#{model.id}"
end
end
2012-07-24 23:26:16 +02:00
2012-07-26 22:26:23 +02:00
version :largest do
2012-07-27 01:08:25 +02:00
process :resize_to_fill => [1170, 600]
def store_dir
2012-07-24 23:26:16 +02:00
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}/#{model.id}"
end
end
2012-07-26 22:26:23 +02:00
######################################################################################################################
# Add a white list of extensions which are allowed to be uploaded,
# for images you might use something like this:
def extension_white_list
%w(jpg jpeg gif png bmp tiff)
end
end