Binary file to BLOB

I need to put image files from filesystem to mysql database.
I don’t have to upload images, they are in the server filesystem
I tried such code in my model , but it don’t work:

    f =, filename))
    data = Mysql.escape_string(
    self.icon = data

Model “Document” has binary field :icon, where I tried to save data from
file, but it only save small portion (190 - 400 bytes).

Please, help.

can you try:

self.icon =, filename), “rb”).read

the important part being “rb” which means read the file directly as
binary data.

sorry I accidently posted my reply to just the author. I think this
might help:

self.icon =, filename) , “rb”).read

The important bit is “rb” which means read the files as binary data.

Thanks, it works.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs