2010-04-13 00:40:47 +02:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
class FileUploader < CarrierWave::Uploader::Base
|
|
|
|
|
|
|
|
# Include RMagick or ImageScience support
|
2011-04-11 06:38:53 +02:00
|
|
|
# include CarrierWave::RMagick
|
2010-04-13 00:40:47 +02:00
|
|
|
# include CarrierWave::ImageScience
|
2011-04-11 06:38:53 +02:00
|
|
|
include CarrierWave::MiniMagick
|
2010-04-13 00:40:47 +02:00
|
|
|
# Choose what kind of storage to use for this uploader
|
2010-04-14 05:56:13 +02:00
|
|
|
if ENV['S3_KEY']
|
|
|
|
storage :s3
|
2010-04-14 07:00:48 +02:00
|
|
|
|
|
|
|
def cache_dir
|
|
|
|
"#{RAILS_ROOT}/tmp/uploads" if ENV['HEROKU'] == 'true'
|
|
|
|
end
|
2010-04-14 05:56:13 +02:00
|
|
|
else
|
|
|
|
storage :file
|
|
|
|
end
|
2010-04-13 00:40:47 +02:00
|
|
|
|
|
|
|
# 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
|
2010-04-13 21:10:40 +02:00
|
|
|
#{}"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
2011-01-12 09:40:39 +01:00
|
|
|
ENV['STORAGE_PATH'] + "/#{model.album.path}"
|
2010-04-13 00:40:47 +02:00
|
|
|
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
|
|
|
|
version :collection do
|
2010-04-13 21:10:40 +02:00
|
|
|
process :resize_to_fill => [200, 200]
|
|
|
|
def store_dir
|
2011-01-12 09:40:39 +01:00
|
|
|
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}"
|
2010-04-13 21:10:40 +02:00
|
|
|
end
|
2010-04-13 00:40:47 +02:00
|
|
|
end
|
|
|
|
version :album do
|
2010-04-13 21:10:40 +02:00
|
|
|
process :resize_to_fill => [100, 100]
|
|
|
|
def store_dir
|
2011-01-12 09:40:39 +01:00
|
|
|
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}"
|
2010-04-13 21:10:40 +02:00
|
|
|
end
|
2010-04-13 00:40:47 +02:00
|
|
|
end
|
|
|
|
version :preview do
|
2010-04-13 21:10:40 +02:00
|
|
|
process :resize_to_fit => [210, 210]
|
|
|
|
def store_dir
|
2011-01-12 09:40:39 +01:00
|
|
|
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}"
|
2010-04-13 21:10:40 +02:00
|
|
|
end
|
2010-04-13 00:40:47 +02:00
|
|
|
end
|
|
|
|
version :single do
|
2010-07-01 12:14:23 +02:00
|
|
|
process :resize_to_limit => [950, 950]
|
2010-04-13 21:10:40 +02:00
|
|
|
def store_dir
|
2011-01-12 09:40:39 +01:00
|
|
|
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}"
|
2010-04-13 21:10:40 +02:00
|
|
|
end
|
2010-04-13 00:40:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# Add a white list of extensions which are allowed to be uploaded,
|
|
|
|
# for images you might use something like this:
|
2010-09-21 21:57:22 +02:00
|
|
|
def extension_white_list
|
|
|
|
%w(jpg jpeg gif png bmp tiff)
|
|
|
|
end
|
2010-04-13 00:40:47 +02:00
|
|
|
|
|
|
|
# Override the filename of the uploaded files
|
|
|
|
# def filename
|
|
|
|
# "something.jpg" if original_filename
|
|
|
|
# end
|
|
|
|
|
|
|
|
end
|