No commit activity in last 3 years
No release in over 3 years
Adds mime type and file extension to Tempfile.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.0.0
~> 1.5.1
 Project Readme

vidibus-tempfile¶ ↑

The extended Temfile class allows temporary files with correct mime type and file extension. This is useful for processing temporary files. Parts of the Tempfile extensions were copied from Paperclip. Thank you!

This gem is part of the open source SOA framework Vidibus: vidibus.org

Installation¶ ↑

Add the dependency to the Gemfile of your application:

gem "vidibus-tempfile"

Then call ‘bundle install` on your console.

Usage¶ ↑

This is an example for extracting image stills from a video through a Tempfile:

# Extract video still using FFmpeg
def extract_image(video, seconds = 10)
  basename = File.basename(video).gsub(/\.\w+$/,'')
  tmpfile = Vidibus::Tempfile.new("#{basename}.jpg")
  tmpfile.binmode
  cmd = %(ffmpeg -itsoffset -#{seconds} -i "#{video}" -y -vcodec mjpeg -qscale 1 -vframes 1 -an -f rawvideo #{File.expand_path(tmpfile.path)} 2>/dev/null)
  `#{cmd}`
  tmp
end

The next example shows how to assign an image by setting its path:

class Image
  include Mongoid::Document
  include Paperclip

  field :image_file_name
  field :image_content_type
  field :image_file_size, :type => Integer

  has_attached_file :image

  def image=(path)
    self.write_attribute(:image, Vidibus::Tempfile.new(path))
  end
end

TODO¶ ↑

  • Write specs

Copyright © 2010 Andre Pankratz. See LICENSE.txt for further details.