While working through an application that allows users to upload videos to the web I ran into a few problems. For starters, there’s no guarantee that obscene videos won’t be uploaded into the application. The integrity of the application will be dependent on members of the community. Or an editorial process could be implemented where videos are reviewed and published upont approval. I wonder if that’s what Google is doing.
At any rate, the purpose of this post is a simple one-liner (most great Ruby on Rails helpers are one-liners) that simplified my development. Not only that, it ensured the types of files being uploaded were videos and nothing else. Rails has access to file metadata and one field in particular known as content_type. In my Rails model I was able to do validation with this method:
validates_format_of :content_type, :with => /^video/, :message => “Only video files are supported”
After testing with .3GPP and .MOV files it worked beautifully. I’m sure the same will hold true for .AVI, .MPG, and .WMV. This method looks for any content-type that is prefixed with video. For example, a Quicktime movie has the content type of video/quicktime. Rails supports all sorts of different validators and I’m looking forward to digging into them.
Hi, I was wondering what you used to send the video data back to your webpage. I’m trying to use Windows embedded media player along with the send_data() function from my controller but I’m not able to get the stream.
Thanks.
Sam,
Thanks for the reply and what I’m currently doing is writing the video file to disk and storing a reference to the video file in the database. Ruby on Rails returns the file path when I make the request and the Flash Video player streams the file. I hope this makes sense and offers some sort of help with your situation.
Regards,
Dennis