title: read the file and convert to a buffer object or use the large object functions
body: <p>Craig Ringer yo no puedo  trabajar con large object functions</p>
  
  <p>My database looks like this</p>
  
  <p>this is my table</p>
  
  <pre><code>-- Table: files
      -- 
  DROP TABLE files;
  
  CREATE TABLE files
  
  (   
  id serial NOT NULL,
  
  orig_filename text NOT NULL,
  
  file_data bytea NOT NULL,
  
  CONSTRAINT files_pkey PRIMARY KEY (id)
  
  )
  
  WITH (
  
  OIDS=FALSE
  
  );
  
  ALTER TABLE files
  </code></pre>
  
  <p>I want save .pdf in my database, I saw you did the last answer, but using python27 (read the file and convert to a buffer object or use the large object functions)</p>
  
  <p>I did the code would look like</p>
  
  <pre><code>path="D:/me/A/Res.pdf"
  listaderuta = path.split("/")
  longitud=len(listaderuta)
  f = open(path,'rb')
  f.read().__str__()
  cursor = con.cursor()
  cursor.execute("INSERT INTO files(id, orig_filename, file_data) VALUES (DEFAULT,%s,%s) RETURNING id", (listaderuta[longitud-1], f.read()))
  </code></pre>
  
  <p>but when I'm downloading, ie save </p>
  
  <pre><code>fula = open("D:/INSTALL/pepe.pdf",'wb')
  cursor.execute("SELECT file_data, orig_filename FROM files WHERE id = %s", (int(17),))
  (file_data, orig_filename) = cursor.fetchone()
  fula.write(file_data)
  fula.close()
  </code></pre>
  
  <p>but when I'm downloading the file can not be opened, this damaged
  I repeat I can not work with large object functions</p>
  
  <p>try this and turned me, can you help ?</p>