title: Saving an audio blob as a file in a rails app
body: <p>I am using recorder.js and have successfully gotten to the point where I can record an audio snippet and play it back over and over again to my heart's content. But now I am trying to make a post of this "blob" (which I know contains proper data since it's playing back correctly) as an audio wav file in my /public folder. My issue is that I am not sure how to deal with the blob and actually post its content. This is my code:</p>
  
  <pre><code>function sendWaveToPost1() {
  console.log(savedWAVBlob);
  
  $.ajax({ url: '/worm/save',
      type: 'POST',
      beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))},
      data: 'someData=' + savedWAVBlob,
      success: function(response) {
          console.log("success");
      }
  });
  </code></pre>
  
  <p>}</p>
  
  <p>Controller:</p>
  
  <pre><code>class WormController &lt; ApplicationController
  
  
   def create
    end
  
    def
  
   save
      audio = params[:someData]
      p audio
      save_path = Rails.root.join("public/audioFiles")
  
      # Open and write the file to file system.
      File.open(save_path, 'wb') do |f|
        f.write audio.read
      end
  
      render :text=&gt; 'hi'
    end
  end
  </code></pre>
  
  <p>That code was based on this post: <a href="https://stackoverflow.com/questions/18801268/save-audio-file-in-rails">Save audio file in rails</a>.
  But although I am posting something, it seems to be a string instead of the actual bytes of the audio file. This is the rails console error I receive: </p>
  
  <pre><code>NoMethodError (undefined method `read' for "[object Blob]":String):
  </code></pre>
  
  <p>Any ideas? I feel like I must be missing some encoding step, or maybe I'm just completely misunderstanding what a blob is. Why can't I just post it directly like this?</p>