title: Retrieving BLOB data from MySQL with Ruby and saving it as file
body: <p>I just want to know how to retrieve BLOB data saved in a database(MySQL) by using Ruby and save the retrieve data as a file in a specific directory.</p>
  
  <p>Let's say I have 'abc.wav' saved as BLOB in DB, and I want my Ruby code to get it from the database and save it in a folder named "sound_files".</p>
  
  <p>Anyone here who knows how to do it?</p>
  
  <p>Edit:
  As of now, I am using the following code as shown below. 
  The problem about it is that the outputted file is only "0 kb" in size which I guess indicates that it is not outputted properly.</p>
  
  <pre><code>wav_data = getWavFiles(db_ip, db_id, db_pass, db_schema)
  wav_data.each do | wav |
      path = "path/to/file" + wav.filename
      File.open(path, 'w')
      File.write(path, wav.blobfile)
  end
  </code></pre>
  
  <p>(Assuming that <code>wav.filename</code> is the filename, and <code>wav.blobfile</code> is the blob data which I both retrieved from the DB)
  Any suggestions about this? Thank you!</p>