= Attached Attached is a Ruby on Rails file attachment tool that lets users upload to the cloud. The gem supports AWS, Google and Rackspace for storage networks by default. It is influenced (and copied) from Paperclip and makes heavy use of the incredibly awesome Fog library. == Requirements The gem is tested with Ruby 1.9.2 and Rails 3.0.6 but may well work with other versions of Ruby and Rails. == Installation gem install attached == Optional brew install imagemagick brew install lame == Examples Migration: rails g model video name:string encoding:attached class CreateVideo < ActiveRecord::Migration def self.up create_table :videos do |t| t.string :name t.attached :encoding t.timestamps end end def self.down drop_table :videos end end Model: class Video < ActiveRecord::Base has_attached :encoding, styles: { webm: { extension: '.webm' }, mp4: { extension: '.mp4' }, ogv: { extension: '.ogv' }, } after_save do remote.encode(self.encoding.url) end end Form: <%= form_for @video, html: { multipart: true } do |form| %> <%= form.file_field :encoding %> <% end %> View: == Advanced === Validations # app/models/person.rb validates_attached_presence :file validates_attached_size :file, in: 2.kilobytes..2.megabytes validates_attached_extension :file, in: %w(jpe jpg jpeg png) ==== Storage # app/models/user.rb has_attached :file, medium: :aws, credentials: "#{Rails.root}/config/aws.yml" # app/models/user.rb has_attached :file, medium: :google, credentials: "#{Rails.root}/config/google.yml" # app/models/user.rb has_attached :file, medium: :rackspace, credentials: "#{Rails.root}/config/rackspace.yml" # config/initializers/attached.rb Attached::Attachment.options[:medium] = :aws Attached::Attachment.options[:credentials] = "#{Rails.root}/config/aws.yml" # config/initializers/attached.rb Attached::Attachment.options[:medium] = :google Attached::Attachment.options[:credentials] = "#{Rails.root}/config/google.yml" # config/initializers/attached.rb Attached::Attachment.options[:medium] = :rackspace Attached::Attachment.options[:credentials] = "#{Rails.root}/config/rackspace.yml" === Processor # app/models/image.rb has_attached :file, processor: :image, styles: { small: { size: '200x200<', extension: '.jpg', quality: 90 }, large: { size: '400x400>', extension: '.jpg', quality: 90 }, default: { size: '300x300#', extension: '.jpg', quality: 90 }, } # app/models/audio.rb has_attached :file, processor: :audio, styles: { full: { preset: '320kbps', extension: '.wav' }, large: { preset: '256kbps', extension: '.wav' }, small: { preset: '128kbps', extension: '.wav' }, } === Reprocessing rake attached:process[Image,file] === Aliases # app/initializer/attached.rb Attached::Attachment.options[:alias] = http://storage.ksylvest.com/ # app/initializer/attached.rb Attached::Attachment.options[:aliases] = %w( http://a.storage.ksylvest.com/ http://b.storage.ksylvest.com/ http://c.storage.ksylvest.com/ http://d.storage.ksylvest.com/ ) == Copyright Copyright (c) 2010 - 2011 Kevin Sylvestre. See LICENSE for details.