[sqlalchemy] Re: Postgre e pg_largeobject
* mercoledì 17 gennaio 2007, alle 09:30, Michael Bayer wrote : print Content-type:text/pdf\n\n# whatever the header is for pdf for chunk in res.pdf: sys.stdout.write(chunk.data) I would agree that the approach taken by pg_largeobject is a useful approach in that you can read just chunked sections. I've converted the column in bytea ... I've realized that I've no benefits using BLOB and pg_largeobject ... and the .pdf is much more usable in this form ... tanks a lot ... -- #include stdio.h int main(void){char c[]={10,65,110,116,111,110,105,111,32,98,97,114,98,111,110, 101,32,60,104,105,110,100,101,109,105,116,64,116,105,115,99,97,108,105,110,101, 116,46,105,116,62,10,10,0};printf(%s,c);return 0;} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Postgre e pg_largeobject
On 1/17/07, Antonio [EMAIL PROTECTED] wrote: and now, how can I retrieve the file (res.pdf.data) in a file or send it as output in a html page (sendig the right headers) ? Nothing magical: file('foo.pdf', 'wb').write(res.pdf.data) see your html framework's docs for instructions on sending back binary data... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Postgre e pg_largeobject
Oops, I didn't notice at first that you are using pg_largeobject... That's not a good idea, you should really use bytea (for SA, that means declaring filepdf as a Binary column itself rather than linking to pg_largeobject) unless you are planning to manually seek inside the lo (i.e. with lo_lseek, etc.), and it doesn't look like you are. I don't believe SA really supports using pg_largeobject, they're kind of obsoleted by bytea. On 1/17/07, Antonio [EMAIL PROTECTED] wrote: Hi all, I'm trying to read a pdf file saved in a postgresql table : pdf_tbl=sqa.Table('pg_largeobject', _mdata, sqa.Column('loid', sqa.Integer, primary_key = True), sqa.Column('pageno', sqa.Integer), sqa.Column('data', sqa.Binary) ) sqa.mapper(Pdf,pdf_tbl) sqa.mapper(Pdf,pdf_tbl) fax_tbl=sqa.Table('faxes', _mdata, sqa.Column('id', sqa.Integer, primary_key = True), sqa.Column('sender', sqa.TEXT), sqa.Column('pages', sqa.SmallInteger), sqa.Column('received', sqa.DateTime), sqa.Column('filepdf', sqa.Integer, sqa.ForeignKey('pg_largeobject.loid')) ) sqa.mapper(Fax,fax_tbl,properties={ 'pdf': sqa.relation(Pdf) }) sess=sqa.create_session() qry=sess.query(Fax) res=qry.get_by(id=1) and now, how can I retrieve the file (res.pdf.data) in a file or send it as output in a html page (sendig the right headers) ? tanks in advance ... PS sorry for my english ... -- #include stdio.h int main(void){char c[]={10,65,110,116,111,110,105,111,32,98,97,114,98,111,110, 101,32,60,104,105,110,100,101,109,105,116,64,116,105,115,99,97,108,105,110,101, 116,46,105,116,62,10,10,0};printf(%s,c);return 0;} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Postgre e pg_largeobject
On Wed, 2007-01-17 at 11:45 +0100, Antonio wrote: Hi all, I'm trying to read a pdf file saved in a postgresql table : and now, how can I retrieve the file (res.pdf.data) in a file or send it as output in a html page (sendig the right headers) ? Antonio, I did a very similar thing (storing largish PDF's) in PostgreSQL and what I did was write an external C program that I let be called as a CGI. Although this approach seems slightly kludgy, it works well for a few reasons: 1. Takes the load off your Python web framework (which tend to be not good at serving large files). 2. Very high performance (will easily saturate 100Mbit if you let it). 3. Most importantly, psycopg (and hence everything that relies on it, e.g. SQLAlchemy) doesn't currently support large objects, so it has to be done some other way. Basically I used this by wrapping it in a simple Python CGI (although the ultimate goal was to make it directly callable from a CGI request w/o any wrapper at all). If you end up doing it this way, then you'll want to figure out a way to prevent unauthorized users from accessing it (either via HTTP AUTH or perhaps even by using one of the deep-link preventing features of your webserver if it has them). Hope this gives you a starting point. Regards, Cliff tanks in advance ... PS sorry for my english ... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~--- pgcatlo.tgz Description: application/compressed-tar