ruby on rails - Read stored file line by line in postgresql carrierwave -
i using carrierwave-postgresql store user uploaded files.
i have uploader called fileuploader (in /app/uploaders/file_uploader.rb) storage :postgresql_lo
.
the uploaded files linked column :file_oid
in model called uploadedfile (in app/models/uploaded_file.rb) mount_uploader :file_oid, fileuploader
:
class uploadedfile < activerecord::base attr_accessible :file_oid, :processed, :type mount_uploader :file_oid, fileuploader end
i upload file as
f = uploadedfile.new f.file_oid = params[:flat_file] f.save!
now when seek read file, read
method works fine, can't 'each' or 'open'.
> uf = uploadedfile.find(:first) > uf.file_oid.read # works, gives contents of file > uf.file_oid.file.read # works > uf.file_oid.file.each nomethoderror: undefined method `each' #<carrierwave::storage::postgresqllo::file:0x000000039157a0> > uf.file_oid.file.open nomethoderror: private method `open' called #<carrierwave::storage::postgresqllo::file:0x000000039157a0> > uf.file_oid.open nomethoderror: private method `open' called /uploadedfile_file_oid/231132:fileuploader
the carrierwave::storage::postgresqllo::file
class doesn't back upwards fancy each
or open
; can't much 1 of objects beyond reading whole thing, writing whole thing, or getting size.
however, if @ read
implementation, you'll see this:
@uploader.model.transaction lo = connection.lo_open(identifier) content = connection.lo_read(lo, file_length) connection.lo_close(lo) content end
so bypass carrierwave-postgresql exclusively , read large object chunk chunk using underlying lo_open
, lo_read
, , lo_close
methods on connection
. won't able read big object line line of course of study big object scheme doesn't know line is, knows seekable byte stream.
ruby-on-rails ruby postgresql carrierwave
No comments:
Post a Comment