Attached

Attached is a Ruby on Rails file attachment tool that lets users upload to the cloud, then process in the cloud. The tool supports Amazon S3 by default. It surpasses Paperclip by providing built-in support for direct uploads to the cloud and by allowing integration with cloud based processing tools. However, in almost every other way Paperclip is better. The source code inspired (and copied) from Paperclip. If you aren’t working in the cloud exclusively then this isn’t for you!

Installation

gem install attached

Examples

Migration:

class CreateVideo < ActiveRecord::Migration
  def self.up
    create_table :videos do |t|
      t.string :video_extension
      t.integer :video_size

      t.timestamps
    end
  end

  def self.down
    drop_table :videos
  end
end

Model:

has_attached :video, :styles => { 
  :mp4_720p => { :extension => 'mp4' },
  :mp4_480p => { :extension => 'mp4' },
  :ogv_720p => { :extension => 'ogv' },
  :ogv_480p => { :extension => 'ogv' },
}

Form:

<%= form_for @video, :html => { :multipart => true } do |form| %>
  <%= form.file_field :video %>
  <p class="errors"><%= @video.errors[:video] %></p>
<% end %>

View:

<video>
  <source src="<%= @video.video.url(:mp4_480p) %>" />
  <source src="<%= @video.video.url(:ogv_480p) %>" />
</video>

Copyright © 2010 Kevin Sylvestre. See LICENSE for details.