rss
twitter
    Find out what I'm doing, Follow Me :)

Uploading video using Mongrel_upload progress and Active Messaging

ActiveMessaging is an attempt to bring the simplicity and elegance of rails development to the world of messaging. Messaging, (or event-driven architecture) is widely used for enterprise integration, with frameworks such as Java's JMS, and products such as ActiveMQ, Tibco, IBM MQSeries, etc.

Download Active Messaging from SVN:

script/plugin install http://activemessaging.googlecode.com/svn/trunk/plugins/activemessaging

For the protocol, ActiveMessaging supports Stomp: Streaming Text-Oriented Messaging Protocol. Stomp is a messaging standard to exchange text based messages over wire connections, usually tcp/ip.

TO install the stomp install the gems:

Assuming you have Rails 1.1+ and MySql already, you'll also need 2 more RubyGems: daemons and Stomp:

sudo gem install daemons
sudo gem install stomp


Download Apache ActiveMQ from
http://activemq.apache.org/

Apache ActiveMQ is the most popular and powerful open source Message Broker and Enterprise Integration Patterns provider.

cd /usr/local/src
#unix and cygwin
wget http://people.apache.org/repo/m2-snapshot-repository/org/apache/activemq/apache-activemq/4.2-SNAPSHOT/apache-activemq-4.2-20070221.081507-10-src.tar.gz
#os x
curl -O http://people.apache.org/repo/m2-snapshot-repository/org/apache/activemq/apache-activemq/4.2-SNAPSHOT/apache-activemq-4.2-20070221.081507-10-src.tar.gz

cd ..
tar xvfz apache-activemq-4.2-20070221.081507-10-src.tar.gz
cd apache-activemq-4.2-incubator-SNAPSHOT
./bin/activemq




Download the sample application using ActiveMessaging and Amazon S3

http://blog.snowonrails.com/articles/2007/05/31/how-to-build-a-mini-youtube-using-activemessaging-plugin-and-amazon-s3



Mongrel Upload Demo
http://itblog.mcgeecorp.com/2007/5/15/mongrel-upload-progress-demo


Install the mongrel_upload progress plugin

gem install mongrel --source=http://mongrel.rubyforge.org/releases/

svn co svn://rubyforge.org/var/svn/mongrel/trunk/projects/mongrel_upload_progress
cd mongrel_upload_progress
rake install



Mongrel_upload useses respond_to_parent function and also mongrel_upload_progress.conf file

Now Active Messaging video uploading as give by the



uses the Amazon S3 address for string the file address. And for that you need API key
and for sure its not free. So I have discovered the alternate to use the localhost for stroing the images.

Its very simple..

In the model video.rb use the following:

VIDEO_BASE = "#{RAILS_ROOT}/public/videos"
VIDEO_UPLOADED = VIDEO_BASE+"/uploaded/"
VIDEO_CONVERTED = VIDEO_BASE+"/converted/"


def video=(video_file)
@temp_file = video_file
self.file_name = video_file.original_filename
self.ext = self.file_name.split('.').last
end

def video_upload_path(file_name=self.file_name)
VIDEO_UPLOADED + file_name
end

def video_convert_path(file_name=convert_file_name)
VIDEO_CONVERTED + "#{id}/"+ file_name
end

def convert_file_name
"#{get_original_filename_without_ext}.flv"
end

def before_create
logger.debug("In before save of video.rb, video_upload_path is:"+video_upload_path+" and video_convert_path is:"+video_convert_path)
save_upload_file
end

def after_create
create_dir
end

private
def get_original_filename_without_ext(filename=self.file_name)
filename.sub(/(.\w+\z)/,"")
end

def create_dir
if !File.exist?(VIDEO_CONVERTED+"#{id}/")
Dir.mkdir(VIDEO_CONVERTED+"#{id}/")
end
end

def save_upload_file
if !File.exist?(VIDEO_BASE)
Dir.mkdir(VIDEO_BASE)
end
if !File.exist?(VIDEO_UPLOADED)
Dir.mkdir(VIDEO_UPLOADED)
end
if !File.exist?(VIDEO_CONVERTED+"#{id}/")
Dir.mkdir(VIDEO_CONVERTED+"#{id}/")
end

File.open(video_upload_path,"wb") do |f|
f.write(@temp_file.read)
end
end



In the broker.yml file use the following settings:

adapter: stomp
login: ""
passcode: ""
host: localhost
port: 61613
reliable: true
reconnectDelay: 5



Now its done.

Start your newly created application as like that:

Start ActiveMQ
Start Rails with mongrel_upload_progress config file
Start Poller
Start DRB server

Bingoooooooooo.

0 comments: