I need to put image files from filesystem to mysql database. I don''t have to upload images, they are in the server filesystem already. I tried such code in my model , but it don''t work: f = File.open(File.join(iconDirPath, filename)) data = Mysql.escape_string(f.read()) self.icon = data self.save 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
sorry I accidently posted my reply to just the author. I think this might help: self.icon = File.open(File.join(iconDirPath, filename) , "rb").read The important bit is "rb" which means read the files as binary data. On Apr 9, 5:52 pm, Al Iv <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I need to put image files from filesystem to mysql database. > I don''t have to upload images, they are in the server filesystem > already. > I tried such code in my model , but it don''t work: > > f = File.open(File.join(iconDirPath, filename)) > data = Mysql.escape_string(f.read()) > self.icon = data > self.save > > 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. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks, it works. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---