Store large binary data without loading it all into memory

12 views
Skip to first unread message

Uwe Kubosch

unread,
Apr 12, 2017, 9:27:11 AM4/12/17
to ruby-pg
Hi all!

I am converting a Rails app to MRI from JRuby and I am looking for a way to store large binary data into a bytea column without having to hold it all in memory.

With JRuby I use the JDBC raw connection and set up streaming:

```ruby
class Image < ActiveRecord::Base
def store_file(filename)
    conn = self.class.connection.raw_connection.connection
is = java.io.FileInputStream.new(java.io.File.new(filename))
st = conn.prepareStatement('UPDATE images SET content_data = ? WHERE id = ?')
st.java_send(:setBinaryStream, [Java::int, java.io.InputStream, Java::int], 1, is, is.available)
st.setInt(2, id)
st.executeUpdate
st.close
  end
end
```

How should I do this with pg?  Any response is welcome :)

--
Uwe Kubosch

Reply all
Reply to author
Forward
0 new messages