I have a problem with uploading a binary file on rails and saving it directly in the database. It''t doesn''t work correctly. I use large objects. The table entry looks as follows: CREATE TABLE pictures ( id serial NOT NULL, description varchar(100), name varchar(100) NOT NULL, content_type varchar(100), data oid NOT NULL, CONSTRAINT pk_pictureid PRIMARY KEY (id) ) I have edited /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/ connection_adapters/postgresql_adapter.rb and added the line: def lo_import(file) @connection.lo_import(file) #calls lo_import from postgres c driver end under the class PostgreSQLAdapter. To import a picture into the database I add the following lines ito the picture model: lo = self.connection().lo_import(picture_field.local_path()) self.data = lo.oid() Now, if I try to upload an Image an error occurs: PGError in Upload controllerController#save could not open large object 16555 I don''t know where the problem lies. Is there someone who has experience with rails, large objects and postgres? Hint''s are welcome. My system properties are: OS: OSX Tiger Ruby: 1.8.4 Postgres: 8.1.4 Postgres Driver: postgres-0.7.1 (C Driver) - works correctly Rails: 1.1.6 -- 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 -~----------~----~----~----~------~----~------~--~---
i dont think its a good idea to save pictures (for a gallery?) in the db, for obvious reasons (just think about performance) in my gallery implementation i used acts_as_file_column (i think that was the name), but that plugin is not developed anymore, acts_as_attachment shall replace it. these plugins save the file on the disk and use a column in the model to store the filename in (or some other technique). this way you can even integrate RMagick or some other sort of processing, creating multiple thumbnails in various sizes and stuff. so my tip is: dont use blobs to store "attachments" regards 2006/10/4, Joel Stillhart <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > > I have a problem with uploading a binary file on rails and saving it > directly in the database. It''t doesn''t work correctly. > > I use large objects. The table entry looks as follows: > > CREATE TABLE pictures > ( > id serial NOT NULL, > description varchar(100), > name varchar(100) NOT NULL, > content_type varchar(100), > data oid NOT NULL, > CONSTRAINT pk_pictureid PRIMARY KEY (id) > ) > > I have edited > > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/ > connection_adapters/postgresql_adapter.rb > > and added the line: > > def lo_import(file) > @connection.lo_import(file) #calls lo_import from postgres c > driver > end > > under the class PostgreSQLAdapter. > > To import a picture into the database I add the following lines ito the > picture model: > > lo = self.connection().lo_import(picture_field.local_path()) > self.data = lo.oid() > > Now, if I try to upload an Image an error occurs: > > PGError in Upload controllerController#save > > could not open large object 16555 > > I don''t know where the problem lies. Is there someone who has experience > with > rails, large objects and postgres? Hint''s are welcome. > > My system properties are: > > OS: OSX Tiger > Ruby: 1.8.4 > Postgres: 8.1.4 > Postgres Driver: postgres-0.7.1 (C Driver) - works correctly > Rails: 1.1.6 > > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Michael Siebert <info-norLuBQQNv0t+8dGM1inlw@public.gmane.org> www.siebert-wd.de - Gedanken lesen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
thank''s for hint''s I need the pictures for blog. That will not be many. regards joel -- 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 -~----------~----~----~----~------~----~------~--~---
It works. I have forgotten to start a transaction. self.connection().execute("BEGIN") lo = self.connection().lo_import(picture_field.local_path()) self.connection().execute("COMMIT") -- 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 -~----------~----~----~----~------~----~------~--~---