Skip to content

Instantly share code, notes, and snippets.

@brand-it
Created July 8, 2011 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brand-it/1071317 to your computer and use it in GitHub Desktop.
Save brand-it/1071317 to your computer and use it in GitHub Desktop.
I am Loving CarrierWave and thought I would share the code I am using on r3dux.net. I have loved its connection information for S3.
# encoding: utf-8
class PhotoUploader < CarrierWave::Uploader::Base
# Include RMagick or ImageScience support:
include CarrierWave::RMagick
# include CarrierWave::ImageScience
# Choose what kind of storage to use for this uploader:
if RAILS_ENV == "development"
storage :file
else
storage :fog
end
version :geo_photo do
process :resize_to_limit => [900, 500]
end
version :small_icon do
process :thumbnail => [40, 40]
end
def thumbnail(width, height)
manipulate! do |img|
img.thumbnail!(width,height)
end
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}"
end
def cache_dir
"#{Rails.root}/tmp/uploads"
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 :thumb do
# process :scale => [50, 50]
# end
# 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)
end
# Override the filename of the uploaded files:
# def filename
# super + '.jpg'
# end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment