Re: uploading files to a database
"Jonathan Ellis" <[email protected]> Thu, 19 Oct 2006 20:40:05 -0700
| Newsgroups | gmane.comp.python.spyce.general |
|---|---|
| Message-ID | <[email protected]> |
your primary problem is not calling response.end() in the handler, that means the script continues outputting html which is going to screw up your pdf a smaller problem is using print instead of response.write (print will add a newline, also not something you want for binary data) btw, instead of data = api.db.uploads.select(db.uploads.c.id==item_id)[0] you can write data = api.db.uploads.selectone_by(id=item_id) On Thu, 19 Oct 2006 09:55:36 +0100, "Mary Jane Boholst" <[email protected]> said: > Thanks for that. I am trying to allow the files which have been uploaded > to > be downloaded and had found that a pdf and jpg file would not display. I > thought that perhaps this could be down to the way that it was stored in > the > db as when I tried to view the data columns in the db for the pdf and > jpg > files it did not show any data. > Looking at what I have done it may be the download script (attached) that > is > not performing correctly as the browser downloads the script rather than > the > file. Perhaps this has something to do with the file being stored in the > db > rather than in a directory? If this is the case how would I go about > storing > uploaded files in a directory on the server and storing the path to the > file > in the db? Is this as straightforward as storing the file in a db? > Any help with deciphering what is going on will be gratefully received. > Sorry > if my query doesn't make much sense... > Thanks in advance, > MJ > > On Wednesday 18 October 2006 19:39, Jonathan Ellis wrote: > > Well, the code looks correct. It works fine for me on sqlite with a > > blob datatype. I don't use mysql so I can't help with longblob... > > although I do know there have been past problems with mysql's > > less-standard types in SqlAlchemy. I would suggest > > > > 1) replace the sqlalchemy directory with lib/sqlalchemy from the latest > > sqlalachemy release > > > > 2) if that fails, you can always use a text column and base64-encode > > what you put into it > > > > 2a) or, just store the file data on the filesystem, and store a pointer > > to that in the database instead of the data itself > > > > -Jonathan > > > > On Wed, 18 Oct 2006 09:14:19 +0100, "Mary Jane Boholst" > > > > <[email protected]> said: > > > the data column in the db is a longblob.... > > > > > > Jonathan Ellis wrote: > > > > what data type is your "data" column in the database? > > > > > > > > On Tue, 17 Oct 2006 11:25:07 +0100, "Mary Jane Boholst" > > > > > > > > <[email protected]> said: > > > >> Hi there, > > > >> Sorry to bother you all again. I have managed to store something in > > > >> the database however I am not sure if this is the binary or not as the > > > >> files do > > > >> not display correctly. Do I need to save the file as a binary version > > > >> before > > > >> entering to the db? I attach my code if it help explain what I have > > > >> done. Thanks in advance for your help. > > > >> Regards, > > > >> MJ > > > >> > > > >> On Thursday 12 October 2006 17:46, Jonathan Ellis wrote: > > > >>> you don't give your code but it looks like you are doing > > > >>> title=request.getpost(something), which returns a list, instead of > > > >>> request.getpost1 > > > >>> > > > >>> On Thu, 12 Oct 2006 15:22:17 +0100, "Mary Jane Boholst" > > > >>> > > > >>> <[email protected]> said: > > > >>>> How do I store the file into a db? I have tried to do this but get > > > >>>> the following errors: > > > >>>> > > > >>>> SQLError: (ProgrammingError) not enough arguments for format string > > > >>>> 'INSERT > > > >>>> INTO uploads (title, data, type) VALUES (%s, %s, %s)' [['test'], > > > >>>> '/data/', > > > >>>> ['text/plain']] > > > >>>> > > > >>>> Stack: /usr/share/spyce-2.1/sqlalchemy/engine/base.py:348, in > > > >>>> _executemany: > > > >>>> > > > >>>> > > > >>>> raise exceptions.SQLError(statement, parameters, e) > > > >>>> > > > >>>> /usr/share/spyce-2.1/sqlalchemy/engine/base.py:319, in _execute_raw: > > > >>>> > > > >>>> > > > >>>> self._executemany(cursor, statement, parameters, context=context) > > > >>>> > > > >>>> /usr/share/spyce-2.1/sqlalchemy/engine/base.py:282, in proxy: > > > >>>> > > > >>>> > > > >>>> self._execute_raw(statement, parameters, cursor=cursor, > > > >>>> context=context) > > > >>>> > > > >>>> /usr/share/spyce-2.1/sqlalchemy/engine/base.py:286, in > > > >>>> execute_compiled: > > > >>>> > > > >>>> > > > >>>> proxy(str(compiled), parameters) > > > >>>> > > > >>>> /usr/share/spyce-2.1/sqlalchemy/engine/base.py:270, in > > > >>>> execute_clauseelement: > > > >>>> > > > >>>> > > > >>>> return self.execute_compiled(elem.compile(engine=self.__engine, > > > >>>> parameters=param), *multiparams, **params) > > > >>>> > > > >>>> /usr/share/spyce-2.1/sqlalchemy/engine/base.py:246, in execute: > > > >>>> > > > >>>> > > > >>>> return Connection.executors[type(object).__mro__[-2]](self, object, > > > >>>> *multiparams, **params) > > > >>>> > > > >>>> /usr/share/spyce-2.1/sqlalchemy/orm/mapper.py:847, in save_obj: > > > >>>> > > > >>>> > > > >>>> c = connection.execute(statement, params) > > > >>>> > > > >>>> /usr/share/spyce-2.1/sqlalchemy/orm/unitofwork.py:599, in > > > >>>> _save_objects: > > > >>>> > > > >>>> > > > >>>> task.mapper.save_obj(task.tosave_objects, trans) > > > >>>> > > > >>>> /usr/share/spyce-2.1/sqlalchemy/orm/unitofwork.py:645, in execute: > > > >>>> > > > >>>> > > > >>>> self._save_objects(trans) > > > >>>> > > > >>>> /usr/share/spyce-2.1/sqlalchemy/orm/unitofwork.py:377, in execute: > > > >>>> > > > >>>> > > > >>>> head.execute(self) > > > >>>> > > > >>>> /usr/share/spyce-2.1/sqlalchemy/orm/unitofwork.py:207, in flush: > > > >>>> > > > >>>> > > > >>>> flush_context.execute(echo=echo) > > > >>>> > > > >>>> /usr/share/spyce-2.1/sqlalchemy/orm/session.py:234, in flush: > > > >>>> > > > >>>> > > > >>>> self.uow.flush(self, objects, echo=self.echo_uow) > > > >>>> > > > >>>> /usr/share/spyce-2.1/sqlalchemy/ext/sqlsoup.py:314, in flush: > > > >>>> > > > >>>> > > > >>>> objectstore.get_session().flush() > > > >>>> > > > >>>> uploadtest.spy:11, in (main): > > > >>>> > > > >>>> > > > >>>> db.flush() > > > >>>> > > > >>>> I am not sure where the problem/s is/are. I feel as if I am going > > > >>>> around in > > > >>>> circles with this. If it will help I attach the file. > > > >>>> Thanks in advance, > > > >>>> MJ > > > >>>> > > > >>>> On Wednesday 11 October 2006 17:01, you wrote: > > > >>>>> You can get the data from request.file and then do whatever you > > > >>>>> like with it > > > >>>>> > > > >>>>> http://spyce.sourceforge.net/docs/fileupload.src.html > > > >>>>> > > > >>>>> On Wed, 11 Oct 2006 15:47:22 +0100, "Mary Jane Boholst" > > > >>>>> > > > >>>>> <[email protected]> said: > > > >>>>>> Hello again, > > > >>>>>> Is it possible to upload files to a database using spyce or even > > > >>>>>> just python? I am aware that files can be uploaded to the browser > > > >>>>>> to display but can these files be stored in a database? Is it > > > >>>>>> possible to just upload files to the server and store information > > > >>>>>> about the file in the database? > > > >>>>>> Sorry to keep bothering you all. > > > >>>>>> Thanks in advance, > > > >>>>>> MJ > > > >>>>>> > > > >>>>>> ------------------------------------------------------------------ > > > >>>>>>--- ---- Using Tomcat but need to do more? Need to support web > > > >>>>>> services, security? Get stuff done quickly with pre-integrated > > > >>>>>> technology to make your job easier > > > >>>>>> Download IBM WebSphere Application Server v.1.0.1 based on Apache > > > >>>>>> Geronimo > > > >>>>>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat= > > > >>>>>>121 642 _______________________________________________ > > > >>>>>> Spyce-users mailing list > > > >>>>>> [email protected] > > > >>>>>> https://lists.sourceforge.net/lists/listinfo/spyce-users -- C++ is history repeated as tragedy. Java is history repeated as farce. --Scott McKay ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642