【发布时间】:2016-03-02 05:36:35
【问题描述】:
在数据库中我有表users。此表具有 mugshot 列,其类型为 mediumblob。我知道这个 mediumblob 的内容类型是image/jpeg。
我想做的是在 ActiveRecord 中编写一个 ruby 脚本,并执行以下操作:
- 遍历
users表中的所有记录 - 根据该 mediumblob 字段中的数据创建一个
.jpg文件 - 根据
users表中的其他列命名文件。示例:“#{user.first_name}_#{user.last_name}.jpg”。
我无法弄清楚的部分是如何从 mediumblob 字段中提取图像,然后将文件命名为我想要的名称:
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
【问题讨论】:
标签: mysql ruby activerecord