Merge branch 'master' of git@github.com:technoweenie/attachment_fu

This commit is contained in:
rick 2009-01-27 15:33:30 -06:00
Родитель 42a37fab15 5b16d05aee
Коммит 95bc6bc296
3 изменённых файлов: 62 добавлений и 16 удалений

Просмотреть файл

@ -50,7 +50,11 @@ module Technoweenie # :nodoc:
# * <tt>:thumbnail_class</tt> - Set what class to use for thumbnails. This attachment class is used by default.
# * <tt>:path_prefix</tt> - path to store the uploaded files. Uses public/#{table_name} by default for the filesystem, and just #{table_name}
# for the S3 backend. Setting this sets the :storage to :file_system.
# * <tt>:storage</tt> - Use :file_system to specify the attachment data is stored with the file system. Defaults to :db_system.
# * <tt>:bucket_key</tt> - Use this to specify a different bucket key other than :bucket_name in the amazon_s3.yml file. This allows you to use
# different buckets for different models. An example setting would be :image_bucket and the you would need to define the name of the corresponding
# bucket in the amazon_s3.yml file.
# * <tt>:keep_profile</tt> By default image EXIF data will be stripped to minimize image size. For small thumbnails this proivides important savings. Picture quality is not affected. Set to false if you want to keep the image profile as is. ImageScience will allways keep EXIF data.
#

Просмотреть файл

@ -18,17 +18,17 @@ module Technoweenie # :nodoc:
# You can sign up for S3 and get access keys by visiting http://aws.amazon.com/s3.
#
# Example configuration (RAILS_ROOT/config/amazon_s3.yml)
#
#
# development:
# bucket_name: appname_development
# access_key_id: <your key>
# secret_access_key: <your key>
#
#
# test:
# bucket_name: appname_test
# access_key_id: <your key>
# secret_access_key: <your key>
#
#
# production:
# bucket_name: appname
# access_key_id: <your key>
@ -81,10 +81,43 @@ module Technoweenie # :nodoc:
#
# Which would result in URLs like <tt>http(s)://:server/:bucket_name/my/custom/path/:id/:filename.</tt>
#
# === Using different bucket names on different models
#
# By default the bucket name that the file will be stored to is the one specified by the
# <tt>:bucket_name</tt> key in the amazon_s3.yml file. You can use the <tt>:bucket_key</tt> option
# to overide this behavior on a per model basis. For instance if you want a bucket that will hold
# only Photos you can do this:
#
# class Photo < ActiveRecord::Base
# has_attachment :storage => :s3, :bucket_key => :photo_bucket_name
# end
#
# And then your amazon_s3.yml file needs to look like this.
#
# development:
# bucket_name: appname_development
# access_key_id: <your key>
# secret_access_key: <your key>
#
# test:
# bucket_name: appname_test
# access_key_id: <your key>
# secret_access_key: <your key>
#
# production:
# bucket_name: appname
# photo_bucket_name: appname_photos
# access_key_id: <your key>
# secret_access_key: <your key>
#
# If the bucket_key you specify is not there in a certain environment then attachment_fu will
# default to the <tt>bucket_name</tt> key. This way you only have to create special buckets
# this can be helpful if you only need special buckets in certain environments.
#
# === Permissions
#
# By default, files are stored on S3 with public access permissions. You can customize this using
# the <tt>:s3_access</tt> option to <tt>has_attachment</tt>. Available values are
# the <tt>:s3_access</tt> option to <tt>has_attachment</tt>. Available values are
# <tt>:private</tt>, <tt>:public_read_write</tt>, and <tt>:authenticated_read</tt>.
#
# === Other options
@ -123,7 +156,7 @@ module Technoweenie # :nodoc:
def self.included(base) #:nodoc:
mattr_reader :bucket_name, :s3_config
begin
require 'aws/s3'
include AWS::S3
@ -138,7 +171,13 @@ module Technoweenie # :nodoc:
# raise ConfigFileNotFoundError.new('File %s not found' % @@s3_config_path)
end
@@bucket_name = s3_config[:bucket_name]
bucket_key = base.attachment_options[:bucket_key]
if bucket_key and s3_config[bucket_key.to_sym]
@@bucket_name = s3_config[bucket_key.to_sym]
else
@@bucket_name = s3_config[:bucket_name]
end
Base.establish_connection!(s3_config.slice(:access_key_id, :secret_access_key, :server, :port, :use_ssl, :persistent, :proxy))
@ -150,11 +189,11 @@ module Technoweenie # :nodoc:
def self.protocol
@protocol ||= s3_config[:use_ssl] ? 'https://' : 'http://'
end
def self.hostname
@hostname ||= s3_config[:server] || AWS::S3::DEFAULT_HOST
end
def self.port_string
@port_string ||= (s3_config[:port].nil? || s3_config[:port] == (s3_config[:use_ssl] ? 443 : 80)) ? '' : ":#{s3_config[:port]}"
end
@ -163,11 +202,11 @@ module Technoweenie # :nodoc:
def s3_protocol
Technoweenie::AttachmentFu::Backends::S3Backend.protocol
end
def s3_hostname
Technoweenie::AttachmentFu::Backends::S3Backend.hostname
end
def s3_port_string
Technoweenie::AttachmentFu::Backends::S3Backend.port_string
end
@ -196,7 +235,7 @@ module Technoweenie # :nodoc:
File.join(base_path, thumbnail_name_for(thumbnail))
end
# All public objects are accessible via a GET request to the S3 servers. You can generate a
# All public objects are accessible via a GET request to the S3 servers. You can generate a
# url for an object using the s3_url method.
#
# @photo.s3_url
@ -211,7 +250,7 @@ module Technoweenie # :nodoc:
end
alias :public_filename :s3_url
# All private objects are accessible via an authenticated GET request to the S3 servers. You can generate an
# All private objects are accessible via an authenticated GET request to the S3 servers. You can generate an
# authenticated url for an object like this:
#
# @photo.authenticated_s3_url
@ -223,7 +262,7 @@ module Technoweenie # :nodoc:
#
# # Absolute expiration date (October 13th, 2025)
# @photo.authenticated_s3_url(:expires => Time.mktime(2025,10,13).to_i)
#
#
# # Expiration in five hours from now
# @photo.authenticated_s3_url(:expires_in => 5.hours)
#
@ -252,11 +291,11 @@ module Technoweenie # :nodoc:
def s3_protocol
Technoweenie::AttachmentFu::Backends::S3Backend.protocol
end
def s3_hostname
Technoweenie::AttachmentFu::Backends::S3Backend.hostname
end
def s3_port_string
Technoweenie::AttachmentFu::Backends::S3Backend.port_string
end
@ -269,7 +308,7 @@ module Technoweenie # :nodoc:
def rename_file
return unless @old_filename && @old_filename != filename
old_full_filename = File.join(base_path, @old_filename)
S3Object.rename(

Просмотреть файл

@ -42,6 +42,9 @@ module Technoweenie # :nodoc:
if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
size = [size, size] if size.is_a?(Fixnum)
img.thumbnail!(*size)
elsif size.is_a?(String) && size =~ /^c.*$/ # Image cropping - example geometry string: c75x75
dimensions = size[1..size.size].split("x")
img.crop_resized!(dimensions[0].to_i, dimensions[1].to_i)
else
img.change_geometry(size.to_s) { |cols, rows, image| image.resize!(cols<1 ? 1 : cols, rows<1 ? 1 : rows) }
end