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.
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".
Anyone here who knows how to do it?
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.
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
(Assuming that wav.filename is the filename, and wav.blobfile is the blob data which I both retrieved from the DB)
Any suggestions about this? Thank you!