Moe Moe - 1 year ago 189
Ruby Question

Ruby on Rails Dragonfly

I have the following Model which has an accessor that receives an audio file with WAV format and then stores it

class Audio < ActiveRecord::Base
belongs_to :contribution
belongs_to :recorder

dragonfly_accessor :audio, :app_name => :videos do
storage_options do |audio|
{ path: "audios/#{}" }


What I want to do is to convert this audio from WAV to MP3 before saving it.

Answer Source

Dragonfly cannot do it by default, you need to add a custom processor and probably use some command line tool for it, here's a few examples

So if you go with one of the top responses from that thread and use libav-tools your custom processor will look something like this (you might also need to change new_path file extension to .mp_3):

processor :to_mp3 do |content|
  content.shell_update do |old_path, new_path|
    "avconv -i #{old_path} #{new_path}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download