The AVChat forums moved to discuss.avchat.net

Jump to content


Photo

Audior on Rails


  • Please log in to reply
4 replies to this topic

#1 colinangevine

colinangevine

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 29 December 2012 - 04:22 PM

Hi all,

I put together a little sample application to try installing Audior in a Ruby on Rails application. It turned out to be very simple:

Frontend
Keep everything the same as the instructions you'll find elsewhere about Audior. Embed the .swf file into your .html exactly the same way.
*Only requirement: point your uploadURL in audior_settings.xml to point to a new route:

Backend
I'll let the code speak for itself:
class AudioClipsController < ApplicationController
  def create
    begin
      @f = File.new("#{Rails.root}/public/audio_clips/#{params[:recordName]}", "wb")
      @f.write(request.raw_post)
      @f.close
      render :text => "save=ok&fileurl=/audio_clips/#{params[:recordName]}"
    rescue
      render :text => "save=fail"
    end
  end
end
Simple as that! When you save from Audior, the data is sent to the path defined in the uploadURL, and if that points to the create action defined here in a controller, you'll see it's just a few lines of Ruby to create a file, write in the request.raw_post data, close the file, and render a successful text message.

Next I'm working on integrating Audior with Transloadit.com so that I can run this kind of a script without writing the mp3 files directly to the webserver (and dealing with the wait time involved in that process), but instead asynchronously save the mp3 to my S3 instance.

#2 colinangevine

colinangevine

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 29 December 2012 - 09:24 PM

Hi all,

Another update: I just tweaked the functionality so that it can save to Amazon S3 instead of the local webserver using the aws/s3 gem. Some sample code:

require "aws/s3"

class AudioClipsController < ApplicationController
  def create
    begin
      AWS::S3::Base.establish_connection!(
          :access_key_id     => 'my-key', 
          :secret_access_key => 'my-secret'
        )
      AWS::S3::S3Object.store(params[:recordName], request.raw_post, "my-bucket-name")
      render :text => "save=ok&fileurl=http://my-bucket-name.s3.amazon.com/#{params[:recordName]}"
    rescue
      puts "Failed to execute properly!"
      render :text => "save=fail"
    end
  end
end

Although this will perform a save directly onto S3, right now I'm trying to figure out if I can run the store() operation using a background worker. I expect that if I have a very long clip, that upload to S3 could potentially hang the whole Rails application.

#3 kirstu

kirstu

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 24 September 2013 - 08:28 AM

Very nice indeed, thank you.

I'm just wondering, how do you deal with the CSRF token. At least for me Rails is complaining about not being able to verify the CSRF token. Is there any way to send that token with the file?

#4 alexanderperls

alexanderperls

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 06 January 2015 - 03:05 PM

Hi, does anyone know how to contact the users in this thread?

We bought Audior, but we are unable to get it to work on a standard Ruby on Rails website.

There is essentially no documentation on Ruby integration beyond this one forum thread.

We tried using the code that "colinagevine" has provided -- we used this to make a new "upload.rb" file, and changed the XML document to point to this file. The recording works fine for us, but the upload to our server always fails.

We are using a very standard Ruby On Rails 4.2 installation on Ubuntu.

We are willing to pay a $500 reward to anyone who can get this working on our server and uploading reliably to Amazon S3..... please contact us directly at info@ezvid.com or via our contact form here: https://www.ezvid.com/contact .. thanks!

#5 Octavian

Octavian

    Founder and CEO

  • Administrators
  • 1,911 posts
  • LocationBucharest, Romania

Posted 29 April 2015 - 08:40 AM

Very nice indeed, thank you.

I'm just wondering, how do you deal with the CSRF token. At least for me Rails is complaining about not being able to verify the CSRF token. Is there any way to send that token with the file?

 

We are currently actively investigating the SCRF issue and will come up with a solution soon.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users