In the database I have the table users. This table has the column mugshot which is of type mediumblob. I know that this mediumblob's content type is image/jpeg.
What I want to do is write a ruby script that requires in ActiveRecord, and does the following:
- iterate through all the records within the
userstable - Create a
.jpgfile from the data within that mediumblob field - name the file according to other columns on the
userstable. Example: "#{user.first_name}_#{user.last_name}.jpg".
The part I am having trouble figuring out is how to rip out the image from that mediumblob field and then name the file what I want:
User.all.each do |user|
# rip out the image from the mediumblob field
# save the file as "#{user.first_name}_#{userlast_name}.jpg"
# save the file within the folder 'my_images' located on the Desktop
end